diff --git a/app/Http/Controllers/BeerController.php b/app/Http/Controllers/BeerController.php index c251364..14a647e 100644 --- a/app/Http/Controllers/BeerController.php +++ b/app/Http/Controllers/BeerController.php @@ -4,18 +4,25 @@ namespace App\Http\Controllers; use App\Models\Beer; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Redirect; class BeerController extends Controller { - public function show() + public function __construct() { + $this->middleware('auth'); + } + public function show(Beer $beer) + { + return view('beer.show', compact('beer')); } public function create() { - return view('beer.create'); + $countries = DB::table('countries')->get(); + return view('beer.create', compact('countries')); } public function store(Request $request) @@ -39,4 +46,42 @@ class BeerController extends Controller return back()->with('success', 'Beer added!'); } + + public function edit(Beer $beer) + { + $countries = DB::table('countries')->get(); + return view('beer.edit', compact('beer', 'countries')); + } + + public function update(Request $request, $id) + { + $this->validate($request, [ + 'beer' => 'required', + 'rating' => 'required', + 'country' => 'required', + 'type' => 'required', + ]); + + $beer = Beer::findOrFail($id); + $beer->beer = $request->beer; + $beer->rating = $request->rating; + $beer->country = $request->country; + $beer->type = $request->type; + $beer->review = $request->review; + + $beer->save(); + + return back()->with('success', 'Beer updated!'); + } + + public function destroy($id) + { + $beer = Beer::findOrFail($id); + + $beer->list()->detach(); + + $beer->delete(); + + return view('profile')->with('success', 'Beer deleted'); + } } diff --git a/app/Http/Controllers/BeerListController.php b/app/Http/Controllers/BeerListController.php index 2794a23..70c8958 100644 --- a/app/Http/Controllers/BeerListController.php +++ b/app/Http/Controllers/BeerListController.php @@ -6,14 +6,22 @@ use App\Models\Beer; use App\Models\BeerList; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; class BeerListController extends Controller { + public function __construct() + { + $this->middleware('auth')->except('show'); + } + public function show(BeerList $list) { $beers = Beer::all(); - return view('list.show', compact('list', 'beers')); + $listBeers = $list->beer()->sortable()->paginate(5); + + return view('list.show', compact('list', 'beers', 'listBeers')); } public function create() @@ -43,6 +51,16 @@ class BeerListController extends Controller $list->beer()->attach($beerId); - return redirect("/list/" . $list->id); + return back()->with('success', 'Beer added'); + } + + public function removeItem(Request $request, $id) + { + $beerId = $request->beer; + $list = BeerList::findOrFail($id); + + $list->beer()->detach($beerId); + + return back()->with('success', 'Beer deleted'); } } diff --git a/app/Models/Beer.php b/app/Models/Beer.php index fa81afe..e39481e 100644 --- a/app/Models/Beer.php +++ b/app/Models/Beer.php @@ -4,11 +4,21 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Kyslik\ColumnSortable\Sortable; class Beer extends Model { use HasFactory; + use Sortable; + + public $sortable = [ + 'beer', + 'rating', + 'country', + 'type' + ]; + public function list() { return $this->belongsToMany(BeerList::class, 'beer_list_pivot', 'beer_id', 'list_id'); diff --git a/composer.json b/composer.json index 5e3dc6a..bc51e44 100644 --- a/composer.json +++ b/composer.json @@ -8,10 +8,12 @@ "php": "^7.3|^8.0", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", + "kyslik/column-sortable": "^6.4", "laravel/framework": "^8.54", "laravel/sanctum": "^2.11", "laravel/tinker": "^2.5", - "laravel/ui": "^3.3" + "laravel/ui": "^3.3", + "webpatser/laravel-countries": "dev-master" }, "require-dev": { "facade/ignition": "^2.5", diff --git a/composer.lock b/composer.lock index 16fdef1..b03d42b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f92dca6b0b8ca69708e45a35a49e4caf", + "content-hash": "e2b5b7e1fad18dd8c4e98f6b71e835af", "packages": [ { "name": "asm89/stack-cors", @@ -877,6 +877,67 @@ }, "time": "2021-06-30T20:03:07+00:00" }, + { + "name": "kyslik/column-sortable", + "version": "6.4.1", + "source": { + "type": "git", + "url": "https://github.com/Kyslik/column-sortable.git", + "reference": "44f9da98acd31b2e871d0074bd638998990888b1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kyslik/column-sortable/zipball/44f9da98acd31b2e871d0074bd638998990888b1", + "reference": "44f9da98acd31b2e871d0074bd638998990888b1", + "shasum": "" + }, + "require": { + "illuminate/database": "5.8.*|^6.0|^7.0|^8.0", + "illuminate/support": "5.8.*|^6.0|^7.0|^8.0", + "php": ">=7.2" + }, + "require-dev": { + "orchestra/testbench": "^5.0", + "phpunit/phpunit": "^8.5" + }, + "type": "package", + "extra": { + "laravel": { + "providers": [ + "Kyslik\\ColumnSortable\\ColumnSortableServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Kyslik\\ColumnSortable\\": "src/ColumnSortable/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Martin Kiesel", + "email": "martin.kiesel@gmail.com", + "role": "Developer and maintainer" + } + ], + "description": "Package for handling column sorting in Laravel 6.x", + "keywords": [ + "column", + "laravel", + "sort", + "sortable", + "sorting" + ], + "support": { + "issues": "https://github.com/Kyslik/column-sortable/issues", + "source": "https://github.com/Kyslik/column-sortable/tree/6.4.1" + }, + "time": "2021-07-09T12:15:54+00:00" + }, { "name": "laravel/framework", "version": "v8.58.0", @@ -5353,6 +5414,73 @@ "source": "https://github.com/webmozarts/assert/tree/1.10.0" }, "time": "2021-03-09T10:59:23+00:00" + }, + { + "name": "webpatser/laravel-countries", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/webpatser/laravel-countries.git", + "reference": "9d656c32c3d92333ab00bd87761e8cd1f7245fb3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webpatser/laravel-countries/zipball/9d656c32c3d92333ab00bd87761e8cd1f7245fb3", + "reference": "9d656c32c3d92333ab00bd87761e8cd1f7245fb3", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "default-branch": true, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Webpatser\\Countries\\CountriesServiceProvider" + ], + "aliases": { + "Countries": "Webpatser\\Countries\\CountriesFacade" + } + } + }, + "autoload": { + "psr-0": { + "Webpatser\\Countries": "src/" + }, + "classmap": [ + "src/commands" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christoph Kempen", + "email": "christoph@downsized.nl", + "homepage": "http://downsized.nl/", + "role": "developer" + }, + { + "name": "Paul Kievits", + "role": "developer" + } + ], + "description": "Laravel Countries is a bundle for Laravel, providing Almost ISO 3166_2, 3166_3, currency, Capital and more for all countries.", + "homepage": "https://github.com/webpatser/laravel-countries", + "keywords": [ + "countries", + "iso_3166_2", + "iso_3166_3", + "laravel" + ], + "support": { + "issues": "https://github.com/webpatser/laravel-countries/issues", + "source": "https://github.com/webpatser/laravel-countries" + }, + "time": "2019-07-12T14:06:05+00:00" } ], "packages-dev": [ @@ -7859,7 +7987,9 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": { + "webpatser/laravel-countries": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/config/app.php b/config/app.php index c9b8f5a..ba5be06 100644 --- a/config/app.php +++ b/config/app.php @@ -161,6 +161,8 @@ return [ Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, + Webpatser\Countries\CountriesServiceProvider::class, + Kyslik\ColumnSortable\ColumnSortableServiceProvider::class, /* * Package Service Providers... @@ -228,6 +230,8 @@ return [ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, + 'Countries' => Webpatser\Countries\CountriesFacade::class, + 'Sortable' => Kyslik\ColumnSortable\ColumnSortableServiceProvider::class, ], diff --git a/config/columnsortable.php b/config/columnsortable.php new file mode 100644 index 0000000..51b54b9 --- /dev/null +++ b/config/columnsortable.php @@ -0,0 +1,121 @@ + [ + 'alpha' => [ + 'rows' => ['description', 'email', 'name', 'slug'], + 'class' => 'fa fa-sort-alpha', + ], + 'amount' => [ + 'rows' => ['amount', 'price'], + 'class' => 'fa fa-sort-amount', + ], + 'numeric' => [ + 'rows' => ['created_at', 'updated_at', 'level', 'id', 'phone_number'], + 'class' => 'fa fa-sort-numeric', + ], + ], + + /* + whether icons should be enabled + */ + 'enable_icons' => true, + + /* + defines icon set to use when sorted data is none above (alpha nor amount nor numeric) + */ + 'default_icon_set' => 'fa fa-sort', + + /* + icon that shows when generating sortable link while column is not sorted + */ + 'sortable_icon' => 'fa fa-sort', + + /* + generated icon is clickable non-clickable (default) + */ + 'clickable_icon' => false, + + /* + icon and text separator (any string) + in case of 'clickable_icon' => true; separator creates possibility to style icon and anchor-text properly + */ + 'icon_text_separator' => ' ', + + /* + suffix class that is appended when ascending direction is applied + */ + 'asc_suffix' => '-asc', + + /* + suffix class that is appended when descending direction is applied + */ + 'desc_suffix' => '-desc', + + /* + default anchor class, if value is null none is added + */ + 'anchor_class' => null, + + /* + default active anchor class, if value is null none is added + */ + 'active_anchor_class' => null, + + /* + default sort direction anchor class, if value is null none is added + */ + 'direction_anchor_class_prefix' => null, + + /* + relation - column separator ex: detail.phone_number means relation "detail" and column "phone_number" + */ + 'uri_relation_column_separator' => '.', + + /* + formatting function applied to name of column, use null to turn formatting off + */ + 'formatting_function' => 'ucfirst', + + /* + apply formatting function to custom titles as well as column names + */ + 'format_custom_titles' => true, + + /* + inject title parameter in query strings, use null to turn injection off + example: 'inject_title' => 't' will result in ..user/?t="formatted title of sorted column" + */ + 'inject_title_as' => null, + + /* + allow request modification, when default sorting is set but is not in URI (first load) + */ + 'allow_request_modification' => true, + + /* + default direction for: $user->sortable('id') usage + */ + 'default_direction' => 'asc', + + /* + default direction for non-sorted columns + */ + 'default_direction_unsorted' => 'asc', + + /* + use the first defined sortable column (Model::$sortable) as default + also applies if sorting parameters are invalid for example: 'sort' => 'name', 'direction' => '' + */ + 'default_first_column' => false, + + /* + join type: join vs leftJoin (default leftJoin) + for more information see https://github.com/Kyslik/column-sortable/issues/59 + */ + 'join_type' => 'leftJoin', +]; diff --git a/config/countries.php b/config/countries.php new file mode 100644 index 0000000..1a2cb17 --- /dev/null +++ b/config/countries.php @@ -0,0 +1,13 @@ + 'countries', +]; diff --git a/database/migrations/2021_09_05_133841_setup_countries_table.php b/database/migrations/2021_09_05_133841_setup_countries_table.php new file mode 100644 index 0000000..51a1750 --- /dev/null +++ b/database/migrations/2021_09_05_133841_setup_countries_table.php @@ -0,0 +1,52 @@ +integer('id')->unsigned()->index(); + $table->string('capital', 255)->nullable(); + $table->string('citizenship', 255)->nullable(); + $table->string('country_code', 3)->default(''); + $table->string('currency', 255)->nullable(); + $table->string('currency_code', 255)->nullable(); + $table->string('currency_sub_unit', 255)->nullable(); + $table->string('currency_symbol', 3)->nullable(); + $table->integer('currency_decimals')->nullable(); + $table->string('full_name', 255)->nullable(); + $table->string('iso_3166_2', 2)->default(''); + $table->string('iso_3166_3', 3)->default(''); + $table->string('name', 255)->default(''); + $table->string('region_code', 3)->default(''); + $table->string('sub_region_code', 3)->default(''); + $table->boolean('eea')->default(0); + $table->string('calling_code', 3)->nullable(); + $table->string('flag', 6)->nullable(); + + $table->primary('id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop(Config::get('countries.table_name')); + } + +} diff --git a/database/migrations/2021_09_05_133842_charify_countries_table.php b/database/migrations/2021_09_05_133842_charify_countries_table.php new file mode 100644 index 0000000..d789d6c --- /dev/null +++ b/database/migrations/2021_09_05_133842_charify_countries_table.php @@ -0,0 +1,40 @@ +getList(); + foreach ($countries as $countryId => $country){ + DB::table(\Config::get('countries.table_name'))->insert(array( + 'id' => $countryId, + 'capital' => ((isset($country['capital'])) ? $country['capital'] : null), + 'citizenship' => ((isset($country['citizenship'])) ? $country['citizenship'] : null), + 'country_code' => $country['country-code'], + 'currency' => ((isset($country['currency'])) ? $country['currency'] : null), + 'currency_code' => ((isset($country['currency_code'])) ? $country['currency_code'] : null), + 'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null), + 'currency_decimals' => ((isset($country['currency_decimals'])) ? $country['currency_decimals'] : null), + 'full_name' => ((isset($country['full_name'])) ? $country['full_name'] : null), + 'iso_3166_2' => $country['iso_3166_2'], + 'iso_3166_3' => $country['iso_3166_3'], + 'name' => $country['name'], + 'region_code' => $country['region-code'], + 'sub_region_code' => $country['sub-region-code'], + 'eea' => (bool)$country['eea'], + 'calling_code' => $country['calling_code'], + 'currency_symbol' => ((isset($country['currency_symbol'])) ? $country['currency_symbol'] : null), + 'flag' =>((isset($country['flag'])) ? $country['flag'] : null), + )); + } + } +} \ No newline at end of file diff --git a/public/css/app.css b/public/css/app.css index b6edbbd..ad389ff 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -55,16 +55,7 @@ Improve consistency of default fonts in all browsers. (https://github.com/sindre */ body { - font-family: - system-ui, - -apple-system, /* Firefox supports this but not yet `system-ui` */ - 'Segoe UI', - Roboto, - Helvetica, - Arial, - sans-serif, - 'Apple Color Emoji', - 'Segoe UI Emoji'; + font-family: 'Titillium Web', sans-serif; } /* @@ -356,7 +347,7 @@ ul { */ html { - font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; /* 1 */ + font-family: 'Titillium Web', sans-serif; line-height: 1.5; /* 2 */ } @@ -526,14 +517,14 @@ samp { * CSS Remedy, with `svg` added as well. * * https://github.com/mozdevs/cssremedy/issues/14 - * + * * 2. Add `vertical-align: middle` to align replaced elements more * sensibly by default when overriding `display` by adding a * utility like `inline`. * * This can trigger a poorly considered linting error in some * tools but is included by design. - * + * * https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210 */ diff --git a/resources/views/beer/create.blade.php b/resources/views/beer/create.blade.php index 6e447fd..f2261aa 100644 --- a/resources/views/beer/create.blade.php +++ b/resources/views/beer/create.blade.php @@ -1,30 +1,51 @@ @extends('layouts.app') @section('content') - Create Beer +

+ Create Beer +

@csrf -