Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
#10 - crud for organization (#34)
Browse files Browse the repository at this point in the history
* #10 - create models and migrations

* #10 - create controller and form requests

* #10 - add basic routing for Organizations

* #10 - create basic CRUD views

* #10 - create input error component

* #10 - change route names

* #10 - create CamelCaseAttributes trait

* #10 - add logo for organizations

* #10 - create class for Formats

* #10 - fix class for Formats
  • Loading branch information
MichalMyskow authored Mar 16, 2022
1 parent 2c02a27 commit ede911f
Show file tree
Hide file tree
Showing 20 changed files with 516 additions and 59 deletions.
5 changes: 4 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
Blumilk\Meetup\Core\Providers\RouteServiceProvider::class,
Blumilk\Meetup\Core\Providers\TelescopeServiceProvider::class,
],
"aliases" => Facade::defaultAliases()->toArray(),
"aliases" => [
Facade::defaultAliases()->toArray(),
"Formats" => Blumilk\Meetup\Core\Formats::class,
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function up(): void
Schema::create("meetups", function (Blueprint $table): void {
$table->id();
$table->foreignId("user_id")->constrained()->onDelete("cascade");
$table->foreignId("organization_id")->nullable()->constrained()->onDelete("set null");
$table->string("title");
$table->text("description")->nullable();
$table->dateTime("date");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
public function up(): void
{
Schema::create("organizations", function (Blueprint $table): void {
$table->id();
$table->string("name");
$table->text("description")->nullable();
$table->string("location");
$table->string("organization_type");
$table->dateTime("foundation_date");
$table->string("number_of_employers");
$table->string("logo");
$table->string("website_url")->nullable();
$table->string("facebook_url")->nullable();
$table->string("linkedin_url")->nullable();
$table->string("instagram_url")->nullable();
$table->string("youtube_url")->nullable();
$table->string("twitter_url")->nullable();
$table->string("github_url")->nullable();
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists("organizations");
}
};
5 changes: 5 additions & 0 deletions resources/views/components/input-error.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@error($for)
<div>
{{ $message }}
</div>
@enderror
32 changes: 6 additions & 26 deletions resources/views/meetups/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,32 @@
<div>
<h1>Create Meetup</h1>
@auth
<form action="{{ route('meetups') }}" method="post">
<form action="{{ route('meetups.store') }}" method="post">
@csrf
<div>
<label for="title">Title:</label>
<input type="text" id="title" name="title" value="{{ old('title') }}">
@error('title')
<div>
{{ $message }}
</div>
@enderror
<x-input-error for="title"/>
</div>
<div>
<label for="description">Description:</label>
<textarea name="description" id="description" cols="30" rows="4">{{ old('description') }}</textarea>
@error('description')
<div>
{{ $message }}
</div>
@enderror
<x-input-error for="description"/>
</div>
<div>
<label for="date">Date:</label>
<input type="dateTime-local" id="date" name="date" value="{{ old('date') }}">
@error('date')
<div>
{{ $message }}
</div>
@enderror
<x-input-error for="date"/>
</div>
<div>
<label for="place">Place:</label>
<input type="text" id="place" name="place" value="{{ old('place') }}">
@error('place')
<div>
{{ $message }}
</div>
@enderror
<x-input-error for="place"/>
</div>
<div>
<label for="language">Language:</label>
<input type="text" id="language" name="language" value="{{ old('language') }}">
@error('language')
<div>
{{ $message }}
</div>
@enderror
<x-input-error for="language"/>
</div>
<div>
<button type="submit">Post</button>
Expand Down
30 changes: 5 additions & 25 deletions resources/views/meetups/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,27 @@
<div>
<label for="title">Title:</label>
<input type="text" id="title" name="title" value="{{ old('title', $meetup->title) }}">
@error('title')
<div>
{{ $message }}
</div>
@enderror
<x-input-error for="title"/>
</div>
<div>
<label for="description">Description:</label>
<textarea name="description" id="description" cols="30" rows="4">{{ old('description', $meetup->description) }}</textarea>
@error('description')
<div>
{{ $message }}
</div>
@enderror
<x-input-error for="description"/>
</div>
<div>
<label for="date">Date:</label>
<input type="dateTime-local" id="date" name="date" value="{{ old('date', $meetup->date) }}">
@error('date')
<div>
{{ $message }}
</div>
@enderror
<x-input-error for="date"/>
</div>
<div>
<label for="place">Place:</label>
<input type="text" id="place" name="place" value="{{ old('place', $meetup->place) }}">
@error('place')
<div>
{{ $message }}
</div>
@enderror
<x-input-error for="place"/>
</div>
<div>
<label for="language">Language:</label>
<input type="text" id="language" name="language" value="{{ old('language', $meetup->language) }}">
@error('language')
<div>
{{ $message }}
</div>
@enderror
<x-input-error for="language"/>
</div>
<div>
<button type="submit">Update</button>
Expand Down
87 changes: 87 additions & 0 deletions resources/views/organizations/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
@extends('layouts.app')

@section('content')
<div>
<div>
<h1>Create Organization</h1>
@auth
<form action="{{ route('organizations.store') }}" method="post" enctype="multipart/form-data">
@csrf
<div>
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="{{ old('name') }}">
<x-input-error for="name"/>
</div>
<div>
<label for="description">Description:</label>
<textarea name="description" id="description" cols="30" rows="4">{{ old('description') }}</textarea>
<x-input-error for="description"/>
</div>
<div>
<label for="location">Location:</label>
<input type="text" id="location" name="location" value="{{ old('location') }}">
<x-input-error for="location"/>
</div>
<div>
<label for="organization_type">Organization type:</label>
<input type="text" id="organization_type" name="organization_type" value="{{ old('organization_type') }}">
<x-input-error for="organization_type"/>
</div>
<div>
<label for="foundation_date">Foundation date:</label>
<input type="dateTime-local" id="foundation_date" name="foundation_date" value="{{ old('foundation_date') }}">
<x-input-error for="foundation_date"/>
</div>
<div>
<label for="number_of_employers">Number of employers:</label>
<input type="text" id="number_of_employers" name="number_of_employers" value="{{ old('number_of_employers') }}">
<x-input-error for="number_of_employers"/>
</div>
<div>
<label for="logo">Logo image:</label>
<input type="file" id="logo" name="logo">
<x-input-error for="logo"/>
</div>
<div>
<label for="website_url">Website:</label>
<input type="text" id="website_url" name="website_url" value="{{ old('website_url') }}">
<x-input-error for="website_url"/>
</div>
<div>
<label for="facebook_url">Facebook:</label>
<input type="text" id="facebook_url" name="facebook_url" value="{{ old('facebook_url') }}">
<x-input-error for="facebook_url"/>
</div>
<div>
<label for="linkedin_url">Linkedin:</label>
<input type="text" id="linkedin_url" name="linkedin_url" value="{{ old('linkedin_url') }}">
<x-input-error for="linkedin_url"/>
</div>
<div>
<label for="instagram_url">Instagram:</label>
<input type="text" id="instagram_url" name="instagram_url" value="{{ old('instagram_url') }}">
<x-input-error for="instagram_url"/>
</div>
<div>
<label for="youtube_url">YouTube:</label>
<input type="text" id="youtube_url" name="youtube_url" value="{{ old('youtube_url') }}">
<x-input-error for="youtube_url"/>
</div>
<div>
<label for="twitter_url">Twitter:</label>
<input type="text" id="twitter_url" name="twitter_url" value="{{ old('twitter_url') }}">
<x-input-error for="twitter_url"/>
</div>
<div>
<label for="github_url">Github:</label>
<input type="text" id="github_url" name="github_url" value="{{ old('github_url') }}">
<x-input-error for="github_url"/>
</div>
<div>
<button type="submit">Create</button>
</div>
</form>
@endauth
</div>
</div>
@endsection
88 changes: 88 additions & 0 deletions resources/views/organizations/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
@extends('layouts.app')

@section('content')
<div>
<div>
<h1>Edit Organization</h1>
@auth
<form method="post" action="{{ route('organizations.update', $organization) }}" enctype="multipart/form-data">
@method('PUT')
@csrf
<div>
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="{{ old('name', $organization->name) }}">
<x-input-error for="name"/>
</div>
<div>
<label for="description">Description:</label>
<textarea name="description" id="description" cols="30" rows="4">{{ old('description', $organization->description) }}</textarea>
<x-input-error for="description"/>
</div>
<div>
<label for="location">Location:</label>
<input type="text" id="location" name="location" value="{{ old('location', $organization->location) }}">
<x-input-error for="location"/>
</div>
<div>
<label for="organization_type">Organization type:</label>
<input type="text" id="organization_type" name="organization_type" value="{{ old('organization_type', $organization->organizationType) }}">
<x-input-error for="organization_type"/>
</div>
<div>
<label for="foundation_date">Foundation date:</label>
<input type="dateTime-local" id="foundation_date" name="foundation_date" value="{{ old('foundation_date', $organization->foundationDate) }}">
<x-input-error for="foundation_date"/>
</div>
<div>
<label for="number_of_employers">Number of employers:</label>
<input type="text" id="number_of_employers" name="number_of_employers" value="{{ old('number_of_employers', $organization->numberOfEmployers) }}">
<x-input-error for="number_of_employers"/>
</div>
<div>
<label for="logo">Logo image:</label>
<input type="file" id="logo" name="logo">
<x-input-error for="logo"/>
</div>
<div>
<label for="website_url">Website:</label>
<input type="text" id="website_url" name="website_url" value="{{ old('website_url', $organization->websiteUrl) }}">
<x-input-error for="website_url"/>
</div>
<div>
<label for="facebook_url">Facebook:</label>
<input type="text" id="facebook_url" name="facebook_url" value="{{ old('facebook_url', $organization->facebookUrl) }}">
<x-input-error for="website_url"/>
</div>
<div>
<label for="linkedin_url">Linkedin:</label>
<input type="text" id="linkedin_url" name="linkedin_url" value="{{ old('linkedin_url', $organization->linkedinUrl) }}">
<x-input-error for="linkedin_url"/>
</div>
<div>
<label for="instagram_url">Instagram:</label>
<input type="text" id="instagram_url" name="instagram_url" value="{{ old('instagram_url', $organization->instagramUrl) }}">
<x-input-error for="instagram_url"/>
</div>
<div>
<label for="youtube_url">YouTube:</label>
<input type="text" id="youtube_url" name="youtube_url" value="{{ old('youtube_url', $organization->youtubeUrl) }}">
<x-input-error for="youtube_url"/>
</div>
<div>
<label for="twitter_url">Twitter:</label>
<input type="text" id="twitter_url" name="twitter_url" value="{{ old('twitter_url', $organization->twitterUrl) }}">
<x-input-error for="twitter_url"/>
</div>
<div>
<label for="github_url">Github:</label>
<input type="text" id="github_url" name="github_url" value="{{ old('github_url', $organization->githubUrl) }}">
<x-input-error for="github_url"/>
</div>
<div>
<button type="submit">Update</button>
</div>
</form>
@endauth
</div>
</div>
@endsection
34 changes: 34 additions & 0 deletions resources/views/organizations/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@extends('layouts.app')

@section('content')
<div>
<div>
<h1>Organizations</h1>
@auth
<a href="{{ route('organizations.create') }}">Create new organization</a>
@endauth
@if ($organizations->count())
@foreach ($organizations as $organization)
<div>
{{ $organization->name }}
{{ $organization->location }}
{{ $organization->organizationType }}
{{ $organization->numberOfEmployers }}
<a href="{{ $organization->websiteUrl }}"> Website </a>

<a href="{{ route('organizations.edit', $organization) }}">Edit</a>
<form action="{{ route('organizations.destroy', $organization) }}" method="post">
@csrf
@method('DELETE')
<button type="submit">Delete</button>
</form>
</div>
@endforeach

{{ $organizations->links() }}
@else
<p>There are no organizations</p>
@endif
</div>
</div>
@endsection
10 changes: 10 additions & 0 deletions src/Formats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Blumilk\Meetup\Core;

class Formats
{
public const DATETIME = "Y-m-d h:i:s";
}
Loading

0 comments on commit ede911f

Please sign in to comment.