diff --git a/app/Article.php b/app/Article.php new file mode 100644 index 0000000..6cb3bd9 --- /dev/null +++ b/app/Article.php @@ -0,0 +1,22 @@ +belongsTo(ArticleCategory::class, 'article_category_id'); + } +} diff --git a/app/ArticleCategory.php b/app/ArticleCategory.php new file mode 100644 index 0000000..2df46a4 --- /dev/null +++ b/app/ArticleCategory.php @@ -0,0 +1,17 @@ +get(); + + return view('article_categories.index', compact('articleCategories')); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + return view('article_categories.create'); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + $articleCategories = new ArticleCategory(); + + $articleCategories->name = $request->input('name'); + $articleCategories->description = $request->input('description'); + + $articleCategories->save(); + + return redirect()->route('article-categories.index') + ->with('success', 'The Article Category: ' . $articleCategories->name . ' has been successfully created!'); + } + + /** + * Display the specified resource. + * + * @param \App\ArticleCategory $articleCategory + * @return \Illuminate\Http\Response + */ + public function show(ArticleCategory $articleCategory) + { + return view('article_categories.show', compact('articleCategory')); + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\ArticleCategory $articleCategory + * @return \Illuminate\Http\Response + */ + public function edit(ArticleCategory $articleCategory) + { + return view('article_categories.edit', compact('articleCategory')); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\ArticleCategory $articleCategory + * @return \Illuminate\Http\Response + */ + public function update(Request $request, ArticleCategory $articleCategory) + { + $articleCategory->name = $request->input('name') ?? $articleCategory->name; + $articleCategory->description = $request->input('description') ?? $articleCategory->description; + + $articleCategory->update(); + + return redirect()->route('article-categories.index') + ->with('success', 'The Article Category: ' . $articleCategory->name . ' has been successfully updated'); + } + + /** + * Remove the specified resource from storage. + * + * @param \App\ArticleCategory $articleCategory + * @return \Illuminate\Http\Response + */ + public function destroy(ArticleCategory $articleCategory) + { + $articleCategory->delete(); + + return redirect()->route('article-categories.index') + ->with('success', 'The Article Category: ' . $articleCategory->name . ' has been successfully deleted!'); + } + + /** + * Delete all selected Article Categories at once. + * + * @param Request $request + */ + public function massDestroy(Request $request) + { + if ($request->input('ids')) { + $entries = ArticleCategory::whereIn('id', $request->input('ids'))->get(); + + foreach ($entries as $entry) { + $entry->delete(); + } + } + } +} diff --git a/app/Http/Controllers/ArticlesController.php b/app/Http/Controllers/ArticlesController.php new file mode 100644 index 0000000..ca8de05 --- /dev/null +++ b/app/Http/Controllers/ArticlesController.php @@ -0,0 +1,135 @@ +orderBy('name', 'asc')->get(); + + return view('articles.index', compact('articles')); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + $relations = [ + 'articleCategories' => \App\ArticleCategory::get()->pluck('name', 'id')->prepend('Please select', ''), + ]; + + return view('articles.create', $relations); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(StoreArticleRequest $request) + { + $article = new Article(); + + $article->name = $request->input('name'); + $article->article_category_id = $request->input('article_category_id'); + $article->url = $request->input('url'); + $article->description = $request->input('description'); + + $article->save(); + + return redirect()->route('articles.index') + ->with('success', 'The Article: ' . $article->name . ' has been successfully created!'); + } + + /** + * Display the specified resource. + * + * @param \App\Article $article + * @return \Illuminate\Http\Response + */ + public function show(Article $article) + { + return view('articles.show', compact('article')); + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\Article $article + * @return \Illuminate\Http\Response + */ + public function edit(Article $article) + { + + $relations = [ + 'article_categories' => \App\ArticleCategory::get()->pluck('name', 'id')->prepend('Please select', ''), + ]; + + return view('articles.edit', compact('article') + $relations); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\Article $article + * @return \Illuminate\Http\Response + */ + public function update(Request $request, Article $article) + { + $article->name = $request->input('name') ?? $article->name; + $article->article_category_id = $request->input('article_category_id') ?? $article->article_category_id; + $article->url = $request->input('url') ?? $article->url; + $article->description = $request->input('description') ?? $article->description; + + $article->update(); + + return redirect()->route('articles.index') + ->with('success', 'The Article: ' . $article->name . ' has been successfully updated'); + } + + /** + * Remove the specified resource from storage. + * + * @param \App\Article $article + * @return \Illuminate\Http\Response + */ + public function destroy(Article $article) + { + $article->delete(); + + return redirect()->route('articles.index') + ->with('success', 'The Article: ' . $article->name . ' has been successfully deleted!'); + } + + /** + * Delete all selected Article Categories at once. + * + * @param Request $request + */ + public function massDestroy(Request $request) + { + if ($request->input('ids')) { + $entries = Article::whereIn('id', $request->input('ids'))->get(); + + foreach ($entries as $entry) { + $entry->delete(); + } + } + } +} diff --git a/app/Http/Requests/StoreArticleRequest.php b/app/Http/Requests/StoreArticleRequest.php new file mode 100644 index 0000000..bc60525 --- /dev/null +++ b/app/Http/Requests/StoreArticleRequest.php @@ -0,0 +1,32 @@ + 'required|max:255', + 'article_category_id' => 'required', + 'url' => 'required', + ]; + } +} diff --git a/config/database.php b/config/database.php index fd22e8e..7c0a878 100644 --- a/config/database.php +++ b/config/database.php @@ -59,11 +59,11 @@ 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), - 'charset' => 'utf8', - 'collation' => 'utf8_unicode_ci', + 'charset' => env('DB_CHARSET', 'utf8'), + 'collation' => env('DB_COLLATION', 'utf8_unicode_ci'), 'prefix' => '', 'strict' => true, - 'engine' => null, + 'engine' => env('DB_ENGINE', null), ], 'pgsql' => [ diff --git a/database/migrations/2018_05_10_072925_create_article_categories_table.php b/database/migrations/2018_05_10_072925_create_article_categories_table.php new file mode 100644 index 0000000..7a9dfa8 --- /dev/null +++ b/database/migrations/2018_05_10_072925_create_article_categories_table.php @@ -0,0 +1,33 @@ +increments('id'); + $table->string('name'); + $table->text('description')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('article_categories'); + } +} diff --git a/database/migrations/2018_05_10_080946_create_articles_table.php b/database/migrations/2018_05_10_080946_create_articles_table.php new file mode 100644 index 0000000..61d204a --- /dev/null +++ b/database/migrations/2018_05_10_080946_create_articles_table.php @@ -0,0 +1,37 @@ +increments('id'); + $table->string('name'); + $table->integer('article_category_id')->unsigned(); + $table->string('url'); + $table->text('description')->nullable(); + $table->timestamps(); + + $table->foreign('article_category_id')->references('id')->on('article_categories'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('articles'); + } +} diff --git a/database/seeds/ArticleCategorySeed.php b/database/seeds/ArticleCategorySeed.php new file mode 100644 index 0000000..76053fa --- /dev/null +++ b/database/seeds/ArticleCategorySeed.php @@ -0,0 +1,49 @@ + 1, + 'name' => 'Laravel::Github-Repositories', + 'description' => 'In this Category we will save every Laravel Repository we would like to Clone to collaborate or review later.' + ], + [ + 'id' => 2, + 'name' => 'Laravel::Packages', + 'description' => 'In this Category we will save the Laravel Packages we use the most, so we can keep our favorite packages in one place.' + ], + [ + 'id' => 3, + 'name' => 'Laravel::Blog-Post', + 'description' => 'In this Category we will save the Laravel Blog-Post we find the most interesting, so we can read it later.' + ], + [ + 'id' => 4, + 'name' => 'Laravel::Video-Tutorials/Lessons', + 'description' => 'In this Category we will save every Laravel Video-Tutorials/Lessons we would like to view later in a free time.' + ], + + [ + 'id' => 5, + 'name' => 'VueJS::Video-Tutorials/Lessons', + 'description' => 'In this Category we will save every VueJS Video-Tutorials/Lessons we would like to view later in a free time.' + ], + + ]; + + foreach ($categories as $category) { + \App\ArticleCategory::create($category); + } + } +} diff --git a/database/seeds/ArticleSeed.php b/database/seeds/ArticleSeed.php new file mode 100644 index 0000000..cfa84e7 --- /dev/null +++ b/database/seeds/ArticleSeed.php @@ -0,0 +1,46 @@ + 'LaravelDaily::Larancer', + 'article_category_id' => 1, + 'url' => 'https://github.com/LaravelDaily/Larancer-QuickAdminPanel', + 'description' => 'Laravel 5.5 system for freelancers to manage their clients/projects/income - generated with QuickAdmin.' + ], + [ + 'name' => 'Barryvdh::Laravel-Debugbar', + 'article_category_id' => 2, + 'url' => 'https://github.com/barryvdh/laravel-debugbar', + 'description' => 'See every event in our app for debugging.' + ], + [ + 'name' => 'LaravelDaily::From Client Dev-Work to Your Product', + 'article_category_id' => 3, + 'url' => 'http://laraveldaily.com/client-dev-work-product-tips-change-mindset/', + 'description' => '7 Tips to Change Your Mindset.' + ], + [ + 'name' => 'VueMastery::Intro to Vue.js', + 'article_category_id' => 5, + 'url' => 'https://www.vuemastery.com/courses/intro-to-vue-js', + 'description' => 'Basic Video Tutorial.' + ], + + ]; + + foreach ($articles as $article) { + \App\Article::create($article); + } + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index d8098e5..79fc53a 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -23,6 +23,8 @@ public function run() $this->call(TransactionTypeSeed::class); $this->call(TransactionSeed::class); $this->call(UserSeed::class); + $this->call(ArticleCategorySeed::class); + $this->call(ArticleSeed::class); $this->command->info('Seeds finished successfully. Admin email: admin@admin.com, Password: password'); } diff --git a/resources/views/article_categories/create.blade.php b/resources/views/article_categories/create.blade.php new file mode 100644 index 0000000..03244c6 --- /dev/null +++ b/resources/views/article_categories/create.blade.php @@ -0,0 +1,45 @@ +@extends('layouts.app') + +@section('content') +

Article Category

+ {!! Form::open(['method' => 'POST', 'route' => ['article-categories.store']]) !!} + +
+
+ Create +
+ +
+
+
+ {!! Form::label('name', '* Name', ['class' => 'control-label']) !!} + {!! Form::text('name', old('name'), ['class' => 'form-control', 'placeholder' => '']) !!} +

+ @if($errors->has('name')) +

+ {{ $errors->first('name') }} +

+ @endif +
+
+
+
+ {!! Form::label('description', 'Description', ['class' => 'control-label']) !!} + {!! Form::textarea('description', old('description'), ['class' => 'form-control ', 'placeholder' => '']) !!} +

+ @if($errors->has('description')) +

+ {{ $errors->first('description') }} +

+ @endif +
+
+ +
+
+ + {!! Form::submit('Save', ['class' => 'btn btn-danger']) !!} + {!! Form::close() !!} +@stop + +@section('javascript')@stop \ No newline at end of file diff --git a/resources/views/article_categories/edit.blade.php b/resources/views/article_categories/edit.blade.php new file mode 100644 index 0000000..ea5386b --- /dev/null +++ b/resources/views/article_categories/edit.blade.php @@ -0,0 +1,46 @@ +@extends('layouts.app') + +@section('content') +

Article Category: {{ $articleCategory->name }}

+ + {!! Form::model($articleCategory, ['method' => 'PUT', 'route' => ['article-categories.update', $articleCategory->id]]) !!} + +
+
+ Edit +
+ +
+
+
+ {!! Form::label('name', 'Name', ['class' => 'control-label']) !!} + {!! Form::text('name', old('name'), ['class' => 'form-control', 'placeholder' => '']) !!} +

+ @if($errors->has('name')) +

+ {{ $errors->first('name') }} +

+ @endif +
+
+
+
+ {!! Form::label('description', 'Description', ['class' => 'control-label']) !!} + {!! Form::textarea('description', old('description'), ['class' => 'form-control ', 'placeholder' => '']) !!} +

+ @if($errors->has('description')) +

+ {{ $errors->first('description') }} +

+ @endif +
+
+ +
+
+ + {!! Form::submit('Update', ['class' => 'btn btn-danger']) !!} + {!! Form::close() !!} +@stop + +@section('javascript')@stop \ No newline at end of file diff --git a/resources/views/article_categories/index.blade.php b/resources/views/article_categories/index.blade.php new file mode 100644 index 0000000..4e9280f --- /dev/null +++ b/resources/views/article_categories/index.blade.php @@ -0,0 +1,70 @@ +@extends('layouts.app') + +@section('styles') + +@endsection + +@section('content') +

Article Categories

+ +

+ Add new +

+ +
+
+ List +
+ +
+ + + + + + + + + + + + @if (count($articleCategories) > 0) + @foreach ($articleCategories as $articleCategory) + + + + + + + @endforeach + @else + + + + @endif + +
NameDescription + +
{{ $articleCategory->name }}{{ $articleCategory->description ?? '' }} + View + Edit + {!! Form::open(array( + 'style' => 'display: inline-block;', + 'method' => 'DELETE', + 'onsubmit' => "return confirm('".trans("Are you sure?")."');", + 'route' => ['article-categories.destroy', $articleCategory->id])) !!} + {!! Form::submit('Delete', array('class' => 'btn btn-xs btn-danger')) !!} + {!! Form::close() !!} +
No entries in table
+
+
+@stop + +@section('javascript') + +@endsection diff --git a/resources/views/article_categories/show.blade.php b/resources/views/article_categories/show.blade.php new file mode 100644 index 0000000..e819d3d --- /dev/null +++ b/resources/views/article_categories/show.blade.php @@ -0,0 +1,37 @@ +@extends('layouts.app') + +@section('content') +

{{ $articleCategory->name }}

+ +
+
+ View +
+ +
+
+
+ + + + + + + + + +
Name{{ $articleCategory->name }}
Description{{ $articleCategory->description }}
+
+
+ +

 

+ + + Back to list + + + Edit + +
+
+@stop \ No newline at end of file diff --git a/resources/views/articles/create.blade.php b/resources/views/articles/create.blade.php new file mode 100644 index 0000000..ded36da --- /dev/null +++ b/resources/views/articles/create.blade.php @@ -0,0 +1,69 @@ +@extends('layouts.app') + +@section('content') +

Create a New Article

+ {!! Form::open(['method' => 'POST', 'route' => ['articles.store']]) !!} + +
+
+ Create +
+ +
+
+
+ {!! Form::label('name', '* Name', ['class' => 'control-label']) !!} + {!! Form::text('name', old('name'), ['class' => 'form-control', 'placeholder' => '']) !!} +

+ @if($errors->has('name')) +

+ {{ $errors->first('name') }} +

+ @endif +
+
+
+
+ {!! Form::label('article_category_id', '* Article Categories', ['class' => 'control-label']) !!} + {!! Form::select('article_category_id', $articleCategories, old('article_category_id'), ['class' => 'form-control']) !!} +

+ @if($errors->has('article_category_id')) +

+ {{ $errors->first('article_category_id') }} +

+ @endif +
+
+
+
+ {!! Form::label('url', '* URL', ['class' => 'control-label']) !!} + {!! Form::text('url', old('url'), ['class' => 'form-control date', 'placeholder' => '']) !!} +

+ @if($errors->has('url')) +

+ {{ $errors->first('url') }} +

+ @endif +
+
+
+
+ {!! Form::label('description', 'Description', ['class' => 'control-label']) !!} + {!! Form::textarea('description', old('description'), ['class' => 'form-control ', 'placeholder' => '']) !!} +

+ @if($errors->has('description')) +

+ {{ $errors->first('description') }} +

+ @endif +
+
+ +
+
+ + {!! Form::submit('Save', ['class' => 'btn btn-danger']) !!} + {!! Form::close() !!} +@stop + +@section('javascript')@stop \ No newline at end of file diff --git a/resources/views/articles/edit.blade.php b/resources/views/articles/edit.blade.php new file mode 100644 index 0000000..53a7985 --- /dev/null +++ b/resources/views/articles/edit.blade.php @@ -0,0 +1,70 @@ +@extends('layouts.app') + +@section('content') +

Article: {{ $article->name }}

+ + {!! Form::model($article, ['method' => 'PUT', 'route' => ['articles.update', $article->id]]) !!} + +
+
+ Edit +
+ +
+
+
+ {!! Form::label('name', 'Name', ['class' => 'control-label']) !!} + {!! Form::text('name', old('name'), ['class' => 'form-control', 'placeholder' => '']) !!} +

+ @if($errors->has('name')) +

+ {{ $errors->first('name') }} +

+ @endif +
+
+
+
+ {!! Form::label('article_category_id', '* Article Categories', ['class' => 'control-label']) !!} + {!! Form::select('article_category_id', $article_categories, old('article_category_id'), ['class' => 'form-control']) !!} +

+ @if($errors->has('article_category_id')) +

+ {{ $errors->first('article_category_id') }} +

+ @endif +
+
+
+
+ {!! Form::label('url', 'URL', ['class' => 'control-label']) !!} + {!! Form::text('url', old('url'), ['class' => 'form-control', 'placeholder' => '']) !!} +

+ @if($errors->has('url')) +

+ {{ $errors->first('url') }} +

+ @endif +
+
+
+
+ {!! Form::label('description', 'Description', ['class' => 'control-label']) !!} + {!! Form::textarea('description', old('description'), ['class' => 'form-control ', 'placeholder' => '']) !!} +

+ @if($errors->has('description')) +

+ {{ $errors->first('description') }} +

+ @endif +
+
+ +
+
+ + {!! Form::submit('Update', ['class' => 'btn btn-danger']) !!} + {!! Form::close() !!} +@stop + +@section('javascript')@stop \ No newline at end of file diff --git a/resources/views/articles/index.blade.php b/resources/views/articles/index.blade.php new file mode 100644 index 0000000..4141b02 --- /dev/null +++ b/resources/views/articles/index.blade.php @@ -0,0 +1,74 @@ +@extends('layouts.app') + +@section('styles') + +@endsection + +@section('content') +

Articles

+ +

+ Add new +

+ +
+
+ List +
+ +
+ + + + + + + + + + + + + @if (count($articles) > 0) + @foreach ($articles as $article) + + + + + + + + @endforeach + @else + + + + @endif + +
NameCategoryDescription + +
{{ $article->name }}{{ $article->category->name }} + {{ $article->description ?? '' }} + + View + Edit + {!! Form::open(array( + 'style' => 'display: inline-block;', + 'method' => 'DELETE', + 'onsubmit' => "return confirm('".trans("Are you sure?")."');", + 'route' => ['articles.destroy', $article->id])) !!} + {!! Form::submit('Delete', array('class' => 'btn btn-xs btn-danger')) !!} + {!! Form::close() !!} +
No entries in table
+
+
+@stop + +@section('javascript') + +@endsection diff --git a/resources/views/articles/show.blade.php b/resources/views/articles/show.blade.php new file mode 100644 index 0000000..6507ab5 --- /dev/null +++ b/resources/views/articles/show.blade.php @@ -0,0 +1,47 @@ +@extends('layouts.app') + +@section('content') +

{{ $article->name }}

+ +
+
+ View +
+ +
+
+
+ + + + + + + + + + + + + + + + + +
Name{{ $article->name }}
Category{{ $article->category->name }}
URL + {{ $article->url }} +
Description{{ $article->description ?? '' }}
+
+
+ +

 

+ + + Back to list + + + Edit + +
+
+@stop \ No newline at end of file diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 9129377..0512249 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -34,6 +34,11 @@

{{ Session::get('message') }}

@endif + @if (session()->has('success')) +
+

{{ session()->get('success') }}

+
+ @endif @if ($errors->count() > 0)