Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couple of code examples updated and their formatting made consistent #478

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions 3.4/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,13 @@ public function setImageAttribute($value)
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);

// 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
3 changes: 3 additions & 0 deletions 3.5/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,13 @@ public function setImageAttribute($value)
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);

// 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
7 changes: 5 additions & 2 deletions 3.6/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -686,13 +686,16 @@ Class Product extends Model
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);

// 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
14 changes: 7 additions & 7 deletions 4.0/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,19 +697,19 @@ Class Product extends Model
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);

// 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
2 changes: 1 addition & 1 deletion 4.1/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ Class Product extends Model
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);

// 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
2 changes: 1 addition & 1 deletion 5.x/crud-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ Class Product extends Model
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);

// 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