From 1e94af11821a569b15fde4f6bf09b9ab8bc43341 Mon Sep 17 00:00:00 2001 From: Toms Binde Date: Wed, 26 Jul 2023 07:31:02 +0300 Subject: [PATCH] Couple of code examples updated and their formatting made consistent --- 3.4/crud-fields.md | 10 ++++++++++ 3.5/crud-columns.md | 2 +- 3.5/crud-fields.md | 10 ++++++++++ 3.6/crud-columns.md | 2 +- 3.6/crud-fields.md | 14 ++++++++++++-- 4.0/crud-columns.md | 2 +- 4.0/crud-fields.md | 19 +++++++++++++------ 4.1/crud-cheat-sheet.md | 4 +++- 4.1/crud-columns.md | 2 +- 4.1/crud-fields.md | 7 +++++++ 4.1/crud-operation-list-entries.md | 4 +++- 5.x/crud-cheat-sheet.md | 4 +++- 5.x/crud-columns.md | 26 +++++++++++++------------- 5.x/crud-fields.md | 7 +++++++ 5.x/crud-operation-list-entries.md | 4 +++- 6.x/crud-columns.md | 26 +++++++++++++------------- 16 files changed, 101 insertions(+), 42 deletions(-) diff --git a/3.4/crud-fields.md b/3.4/crud-fields.md index 399972a5..f9f75407 100644 --- a/3.4/crud-fields.md +++ b/3.4/crud-fields.md @@ -646,10 +646,20 @@ public function setImageAttribute($value) { // 0. Make the image $image = \Image::make($value)->encode('jpg', 90); + + // resize the image so that the largest side fits within the limit; + // the smaller side will be scaled to maintain the original aspect ratio + //$image->resize(1920, null, function ($constraint) { + // $constraint->aspectRatio(); + // $constraint->upsize(); + //}); + // 1. Generate a filename. $filename = md5($value.time()).'.jpg'; + // 2. Store the image on disk. \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream()); + // 3. Save the path to the database $this->attributes[$attribute_name] = $destination_path.'/'.$filename; } diff --git a/3.5/crud-columns.md b/3.5/crud-columns.md index 6b089e37..1117d26c 100644 --- a/3.5/crud-columns.md +++ b/3.5/crud-columns.md @@ -593,7 +593,7 @@ $this->crud->addColumn([ // Select 'attribute' => 'name', // foreign key attribute that is shown to user 'orderable' => true, 'orderLogic' => function ($query, $column, $columnDirection) { - return $query->leftJoin('categories', 'categories.id', '=', 'articles.select') + return $query->leftJoin('categories', 'categories.id', '=', 'articles.category_id') ->orderBy('categories.name', $columnDirection)->select('articles.*'); } ]); diff --git a/3.5/crud-fields.md b/3.5/crud-fields.md index 187debc8..33c4d488 100644 --- a/3.5/crud-fields.md +++ b/3.5/crud-fields.md @@ -684,10 +684,20 @@ public function setImageAttribute($value) { // 0. Make the image $image = \Image::make($value)->encode('jpg', 90); + + // resize the image so that the largest side fits within the limit; + // the smaller side will be scaled to maintain the original aspect ratio + //$image->resize(1920, null, function ($constraint) { + // $constraint->aspectRatio(); + // $constraint->upsize(); + //}); + // 1. Generate a filename. $filename = md5($value.time()).'.jpg'; + // 2. Store the image on disk. \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream()); + // 3. Save the path to the database $this->attributes[$attribute_name] = $destination_path.'/'.$filename; } diff --git a/3.6/crud-columns.md b/3.6/crud-columns.md index a835fb3c..b6e504b3 100644 --- a/3.6/crud-columns.md +++ b/3.6/crud-columns.md @@ -612,7 +612,7 @@ $this->crud->addColumn([ // Select 'attribute' => 'name', // foreign key attribute that is shown to user 'orderable' => true, 'orderLogic' => function ($query, $column, $columnDirection) { - return $query->leftJoin('categories', 'categories.id', '=', 'articles.select') + return $query->leftJoin('categories', 'categories.id', '=', 'articles.category_id') ->orderBy('categories.name', $columnDirection)->select('articles.*'); } ]); diff --git a/3.6/crud-fields.md b/3.6/crud-fields.md index e2e889b1..96ec7449 100644 --- a/3.6/crud-fields.md +++ b/3.6/crud-fields.md @@ -686,13 +686,23 @@ Class Product extends Model { // 0. Make the image $image = \Image::make($value)->encode('jpg', 90); + + // resize the image so that the largest side fits within the limit; + // the smaller side will be scaled to maintain the original aspect ratio + //$image->resize(1920, null, function ($constraint) { + // $constraint->aspectRatio(); + // $constraint->upsize(); + //}); + // 1. Generate a filename. $filename = md5($value.time()).'.jpg'; + // 2. Store the image on disk. \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream()); + // 3. Save the public path to the database - // but first, remove "public/" from the path, since we're pointing to it from the root folder - // that way, what gets saved in the database is the user-accesible URL + // but first, remove "public/" from the path, since we're pointing to it from the root folder + // that way, what gets saved in the database is the user-accesible URL $public_destination_path = Str::replaceFirst('public/', '', $destination_path); $this->attributes[$attribute_name] = $public_destination_path.'/'.$filename; } diff --git a/4.0/crud-columns.md b/4.0/crud-columns.md index ab7ab564..a03dc5ef 100644 --- a/4.0/crud-columns.md +++ b/4.0/crud-columns.md @@ -629,7 +629,7 @@ $this->crud->addColumn([ 'attribute' => 'name', // foreign key attribute that is shown to user 'orderable' => true, 'orderLogic' => function ($query, $column, $columnDirection) { - return $query->leftJoin('categories', 'categories.id', '=', 'articles.select') + return $query->leftJoin('categories', 'categories.id', '=', 'articles.category_id') ->orderBy('categories.name', $columnDirection)->select('articles.*'); } ]); diff --git a/4.0/crud-fields.md b/4.0/crud-fields.md index d8dca2fb..0e083ccd 100644 --- a/4.0/crud-fields.md +++ b/4.0/crud-fields.md @@ -697,19 +697,26 @@ Class Product extends Model { // 0. Make the image $image = \Image::make($value)->encode('jpg', 90); + + // resize the image so that the largest side fits within the limit; + // the smaller side will be scaled to maintain the original aspect ratio + //$image->resize(1920, null, function ($constraint) { + // $constraint->aspectRatio(); + // $constraint->upsize(); + //}); - // 1. Generate a filename. + // 1. Generate a filename. $filename = md5($value.time()).'.jpg'; - // 2. Store the image on disk. + // 2. Store the image on disk. \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream()); - - // 3. Delete the previous image, if there was one. + + // 3. Delete the previous image, if there was one. \Storage::disk($disk)->delete($this->{$attribute_name}); // 4. Save the public path to the database - // but first, remove "public/" from the path, since we're pointing to it from the root folder - // that way, what gets saved in the database is the user-accesible URL + // but first, remove "public/" from the path, since we're pointing to it from the root folder + // that way, what gets saved in the database is the user-accesible URL $public_destination_path = Str::replaceFirst('public/', '', $destination_path); $this->attributes[$attribute_name] = $public_destination_path.'/'.$filename; diff --git a/4.1/crud-cheat-sheet.md b/4.1/crud-cheat-sheet.md index 7f507e6d..c55c8a1b 100644 --- a/4.1/crud-cheat-sheet.md +++ b/4.1/crud-cheat-sheet.md @@ -165,8 +165,10 @@ $this->crud->addClause('whereHas', 'posts', function($query) { $this->crud->groupBy(); $this->crud->limit(); +// please note it's generally a good idea to use crud->orderBy() inside +// "if (!$this->crud->getRequest()->has('order')) {}"; +// that way, your custom order is applied ONLY IF the user hasn't forced another order (by clicking a column heading) $this->crud->orderBy(); -// please note it's generally a good idea to use crud->orderBy() inside "if (!$this->crud->getRequest()->has('order')) {}"; that way, your custom order is applied ONLY IF the user hasn't forced another order (by clicking a column heading) ``` diff --git a/4.1/crud-columns.md b/4.1/crud-columns.md index 117a482f..99366cba 100644 --- a/4.1/crud-columns.md +++ b/4.1/crud-columns.md @@ -796,7 +796,7 @@ $this->crud->addColumn([ 'attribute' => 'name', // foreign key attribute that is shown to user 'orderable' => true, 'orderLogic' => function ($query, $column, $columnDirection) { - return $query->leftJoin('categories', 'categories.id', '=', 'articles.select') + return $query->leftJoin('categories', 'categories.id', '=', 'articles.category_id') ->orderBy('categories.name', $columnDirection)->select('articles.*'); } ]); diff --git a/4.1/crud-fields.md b/4.1/crud-fields.md index 3a5ff7dd..205b5a01 100644 --- a/4.1/crud-fields.md +++ b/4.1/crud-fields.md @@ -899,6 +899,13 @@ Class Product extends Model { // 0. Make the image $image = \Image::make($value)->encode('jpg', 90); + + // resize the image so that the largest side fits within the limit; + // the smaller side will be scaled to maintain the original aspect ratio + //$image->resize(1920, null, function ($constraint) { + // $constraint->aspectRatio(); + // $constraint->upsize(); + //}); // 1. Generate a filename. $filename = md5($value.time()).'.jpg'; diff --git a/4.1/crud-operation-list-entries.md b/4.1/crud-operation-list-entries.md index f2dc38a5..a7547aa3 100644 --- a/4.1/crud-operation-list-entries.md +++ b/4.1/crud-operation-list-entries.md @@ -162,8 +162,10 @@ $this->crud->addClause('whereHas', 'posts', function($query) { $this->crud->groupBy(); $this->crud->limit(); +// please note it's generally a good idea to use crud->orderBy() inside +// "if (!$this->crud->getRequest()->has('order')) {}"; +// that way, your custom order is applied ONLY IF the user hasn't forced another order (by clicking a column heading) $this->crud->orderBy(); -// please note it's generally a good idea to use crud->orderBy() inside "if (!$this->crud->getRequest()->has('order')) {}"; that way, your custom order is applied ONLY IF the user hasn't forced another order (by clicking a column heading) ``` diff --git a/5.x/crud-cheat-sheet.md b/5.x/crud-cheat-sheet.md index 8ce3d0bd..be21b056 100644 --- a/5.x/crud-cheat-sheet.md +++ b/5.x/crud-cheat-sheet.md @@ -173,8 +173,10 @@ $this->crud->addClause('whereHas', 'posts', function($query) { $this->crud->groupBy(); $this->crud->limit(); +// please note it's generally a good idea to use crud->orderBy() inside +// "if (!$this->crud->getRequest()->has('order')) {}"; +// that way, your custom order is applied ONLY IF the user hasn't forced another order (by clicking a column heading) $this->crud->orderBy(); -// please note it's generally a good idea to use crud->orderBy() inside "if (!$this->crud->getRequest()->has('order')) {}"; that way, your custom order is applied ONLY IF the user hasn't forced another order (by clicking a column heading) ``` diff --git a/5.x/crud-columns.md b/5.x/crud-columns.md index 0d72296b..a08fa3d8 100644 --- a/5.x/crud-columns.md +++ b/5.x/crud-columns.md @@ -473,18 +473,18 @@ Shows the number of items that are related to the current entry, for a particula ```php [ - // relationship count - 'name' => 'tags', // name of relationship method in the model - 'type' => 'relationship_count', - 'label' => 'Tags', // Table column heading - // OPTIONAL - // 'suffix' => ' tags', // to show "123 tags" instead of "123 items" - - // if you need that column to be orderable in table, you need to manually provide the orderLogic - // 'orderable' => true, - // 'orderLogic' => function ($query, $column, $columnDirection) { - $query->orderBy('tags_count', $columnDirection); - }, + // relationship count + 'name' => 'tags', // name of relationship method in the model + 'type' => 'relationship_count', + 'label' => 'Tags', // Table column heading + // OPTIONAL + // 'suffix' => ' tags', // to show "123 tags" instead of "123 items" + + // if you need that column to be orderable in table, you need to manually provide the orderLogic + 'orderable' => true, + 'orderLogic' => function ($query, $column, $columnDirection) { + $query->orderBy('tags_count', $columnDirection); + }, ], ``` @@ -868,7 +868,7 @@ $this->crud->addColumn([ 'attribute' => 'name', // foreign key attribute that is shown to user 'orderable' => true, 'orderLogic' => function ($query, $column, $columnDirection) { - return $query->leftJoin('categories', 'categories.id', '=', 'articles.select') + return $query->leftJoin('categories', 'categories.id', '=', 'articles.category_id') ->orderBy('categories.name', $columnDirection)->select('articles.*'); } ]); diff --git a/5.x/crud-fields.md b/5.x/crud-fields.md index 648053a7..d488f4c7 100644 --- a/5.x/crud-fields.md +++ b/5.x/crud-fields.md @@ -1654,6 +1654,13 @@ Class Product extends Model { // 0. Make the image $image = \Image::make($value)->encode('jpg', 90); + + // resize the image so that the largest side fits within the limit; + // the smaller side will be scaled to maintain the original aspect ratio + //$image->resize(1920, null, function ($constraint) { + // $constraint->aspectRatio(); + // $constraint->upsize(); + //}); // 1. Generate a filename. $filename = md5($value.time()).'.jpg'; diff --git a/5.x/crud-operation-list-entries.md b/5.x/crud-operation-list-entries.md index b3ed6835..94a73ba1 100644 --- a/5.x/crud-operation-list-entries.md +++ b/5.x/crud-operation-list-entries.md @@ -209,8 +209,10 @@ $this->crud->limit(); // you can change the baseQuery instead, by using: $this->crud->addBaseClause('where', 'name', '=', 'car'); +// please note it's generally a good idea to use crud->orderBy() inside +// "if (!$this->crud->getRequest()->has('order')) {}"; +// that way, your custom order is applied ONLY IF the user hasn't forced another order (by clicking a column heading) $this->crud->orderBy(); -// please note it's generally a good idea to use crud->orderBy() inside "if (!$this->crud->getRequest()->has('order')) {}"; that way, your custom order is applied ONLY IF the user hasn't forced another order (by clicking a column heading) ``` **NOTE:** The query constraints added in the `setup()` method operation _cannot_ be reset by `Reset Button`. They are permanent for that CRUD, for all operation. diff --git a/6.x/crud-columns.md b/6.x/crud-columns.md index 9b83c0c6..341de157 100644 --- a/6.x/crud-columns.md +++ b/6.x/crud-columns.md @@ -613,18 +613,18 @@ Shows the number of items that are related to the current entry, for a particula ```php [ - // relationship count - 'name' => 'tags', // name of relationship method in the model - 'type' => 'relationship_count', - 'label' => 'Tags', // Table column heading - // OPTIONAL - // 'suffix' => ' tags', // to show "123 tags" instead of "123 items" - - // if you need that column to be orderable in table, you need to manually provide the orderLogic - // 'orderable' => true, - // 'orderLogic' => function ($query, $column, $columnDirection) { - $query->orderBy('tags_count', $columnDirection); - }, + // relationship count + 'name' => 'tags', // name of relationship method in the model + 'type' => 'relationship_count', + 'label' => 'Tags', // Table column heading + // OPTIONAL + // 'suffix' => ' tags', // to show "123 tags" instead of "123 items" + + // if you need that column to be orderable in table, you need to manually provide the orderLogic + 'orderable' => true, + 'orderLogic' => function ($query, $column, $columnDirection) { + $query->orderBy('tags_count', $columnDirection); + }, ], ``` @@ -1529,7 +1529,7 @@ $this->crud->addColumn([ 'attribute' => 'name', // foreign key attribute that is shown to user 'orderable' => true, 'orderLogic' => function ($query, $column, $columnDirection) { - return $query->leftJoin('categories', 'categories.id', '=', 'articles.select') + return $query->leftJoin('categories', 'categories.id', '=', 'articles.category_id') ->orderBy('categories.name', $columnDirection)->select('articles.*'); } ]);