Skip to content

Commit

Permalink
Couple of code examples updated and their formatting made consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsb committed Jul 26, 2023
1 parent bdb9623 commit 1e94af1
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 42 deletions.
10 changes: 10 additions & 0 deletions 3.4/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion 3.5/crud-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.*');
}
]);
Expand Down
10 changes: 10 additions & 0 deletions 3.5/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion 3.6/crud-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.*');
}
]);
Expand Down
14 changes: 12 additions & 2 deletions 3.6/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion 4.0/crud-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.*');
}
]);
Expand Down
19 changes: 13 additions & 6 deletions 4.0/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion 4.1/crud-cheat-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

<a name="show-api"></a>
Expand Down
2 changes: 1 addition & 1 deletion 4.1/crud-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.*');
}
]);
Expand Down
7 changes: 7 additions & 0 deletions 4.1/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 3 additions & 1 deletion 4.1/crud-operation-list-entries.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

<a name="responsive-table"></a>
Expand Down
4 changes: 3 additions & 1 deletion 5.x/crud-cheat-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

<a name="show-api"></a>
Expand Down
26 changes: 13 additions & 13 deletions 5.x/crud-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
],
```

Expand Down Expand Up @@ -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.*');
}
]);
Expand Down
7 changes: 7 additions & 0 deletions 5.x/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 3 additions & 1 deletion 5.x/crud-operation-list-entries.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
26 changes: 13 additions & 13 deletions 6.x/crud-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
],
```

Expand Down Expand Up @@ -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.*');
}
]);
Expand Down

0 comments on commit 1e94af1

Please sign in to comment.