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') +
+ {{ $errors->first('name') }} +
+ @endif ++ {{ $errors->first('description') }} +
+ @endif ++ {{ $errors->first('name') }} +
+ @endif ++ {{ $errors->first('description') }} +
+ @endif ++ Add new +
+ +| + | Name | +Description | ++ + | +||||
|---|---|---|---|---|---|---|---|
| + | {{ $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 | +|||||||
| Name | +{{ $articleCategory->name }} | +
|---|---|
| Description | +{{ $articleCategory->description }} | +
+ + + Back to list + + + Edit + +
+ {{ $errors->first('name') }} +
+ @endif ++ {{ $errors->first('article_category_id') }} +
+ @endif ++ {{ $errors->first('url') }} +
+ @endif ++ {{ $errors->first('description') }} +
+ @endif ++ {{ $errors->first('name') }} +
+ @endif ++ {{ $errors->first('article_category_id') }} +
+ @endif ++ {{ $errors->first('url') }} +
+ @endif ++ {{ $errors->first('description') }} +
+ @endif ++ Add new +
+ +| + | Name | +Category | +Description | ++ + | +|||
|---|---|---|---|---|---|---|---|
| + | {{ $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 | +|||||||
| Name | +{{ $article->name }} | +
|---|---|
| Category | +{{ $article->category->name }} | +
| URL | ++ {{ $article->url }} + | +
| Description | +{{ $article->description ?? '' }} | +
+ + + Back to list + + + Edit + +
{{ Session::get('message') }}
@endif + @if (session()->has('success')) +{{ session()->get('success') }}
+