Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Apply fixes from StyleCI
  • Loading branch information
tabacitu authored and StyleCIBot committed Dec 3, 2019
commit e67fb24e691d502cec6c298684ef9d76e8719ff7
17 changes: 8 additions & 9 deletions app/Http/Controllers/Admin/CreatorCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace App\Http\Controllers\Admin;

use App\Http\Requests\CreatorRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;

/**
* Class CreatorCrudController
* @package App\Http\Controllers\Admin
* Class CreatorCrudController.
*
* @property-read CrudPanel $crud
*/
class CreatorCrudController extends CrudController
Expand All @@ -18,21 +17,21 @@ class CreatorCrudController extends CrudController
public function setup()
{
$this->crud->setModel('App\Models\Creator');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/creator');
$this->crud->setRoute(config('backpack.base.route_prefix').'/creator');
$this->crud->setEntityNameStrings('creator', 'creators');
}

protected function setupListOperation()
{
$this->crud->addColumn('name');
$this->crud->addColumn([
'type' => 'relationship_count',
'name' => 'snippets',
'label' => 'Snippets',
'type' => 'relationship_count',
'name' => 'snippets',
'label' => 'Snippets',
'suffix' => ' snippets',
'link' => function($entry) {
'link' => function ($entry) {
return backpack_url('creator/'.$entry->id.'/snippet');
}
},
]);
}
}
8 changes: 3 additions & 5 deletions app/Http/Controllers/Admin/CreatorSnippetCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace App\Http\Controllers\Admin;

use App\Http\Requests\SnippetRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;

/**
* Class SnippetCrudController
* @package App\Http\Controllers\Admin
* Class SnippetCrudController.
*
* @property-read CrudPanel $crud
*/
class CreatorSnippetCrudController extends SnippetCrudController
Expand All @@ -24,7 +22,7 @@ public function setup()
$user_id = \Route::current()->parameter('user_id');

$this->crud->setModel('App\Models\Snippet');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/creator/'.$user_id.'/snippet');
$this->crud->setRoute(config('backpack.base.route_prefix').'/creator/'.$user_id.'/snippet');
$this->crud->setEntityNameStrings('snippet', 'snippets');

// filter List operation (with search) to only show this users' entries
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Admin/MonsterCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,10 @@ protected function setupCreateOperation()
]);

$this->crud->addField([ // Browse multiple
'name' => 'browse_multiple',
'label' => 'Browse multiple',
'type' => 'browse_multiple',
'tab' => 'Uploads',
'name' => 'browse_multiple',
'label' => 'Browse multiple',
'type' => 'browse_multiple',
'tab' => 'Uploads',
'sortable' => true,
// 'multiple' => true, // enable/disable the multiple selection functionality
// 'mime_types' => null, // visible mime prefixes; ex. ['image'] or ['application/pdf']
Expand Down
10 changes: 4 additions & 6 deletions app/Http/Controllers/Admin/MySnippetCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace App\Http\Controllers\Admin;

use App\Http\Requests\SnippetRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;

/**
* Class SnippetCrudController
* @package App\Http\Controllers\Admin
* Class SnippetCrudController.
*
* @property-read CrudPanel $crud
*/
class MySnippetCrudController extends SnippetCrudController
Expand All @@ -22,15 +20,15 @@ class MySnippetCrudController extends SnippetCrudController
public function setup()
{
$this->crud->setModel('App\Models\Snippet');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/my-snippet');
$this->crud->setRoute(config('backpack.base.route_prefix').'/my-snippet');
$this->crud->setEntityNameStrings('snippet', 'snippets');

// filter List operation (with search) to only show this users' entries
$this->crud->addClause('where', 'created_by', backpack_auth()->user()->id);

// if the user tries to access somone else's entries, block him
$entry = $this->crud->getCurrentEntry();

if ($entry && $entry->created_by != backpack_auth()->user()->id) {
abort(403, "You don't have access to this entry.");
}
Expand Down
68 changes: 34 additions & 34 deletions app/Http/Controllers/Admin/SnippetCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;

/**
* Class SnippetCrudController
* @package App\Http\Controllers\Admin
* Class SnippetCrudController.
*
* @property-read CrudPanel $crud
*/
class SnippetCrudController extends CrudController
Expand All @@ -22,41 +22,41 @@ class SnippetCrudController extends CrudController
public function setup()
{
$this->crud->setModel('App\Models\Snippet');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/snippet');
$this->crud->setRoute(config('backpack.base.route_prefix').'/snippet');
$this->crud->setEntityNameStrings('snippet', 'snippets');
}

protected function setupListOperation()
{
$this->crud->addColumn('name');
$this->crud->addColumn([
'label' => 'Category',
'type' => 'select',
'name' => 'category_id',
'entity' => 'category',
'label' => 'Category',
'type' => 'select',
'name' => 'category_id',
'entity' => 'category',
'attribute' => 'name',
]);
$this->crud->addColumn([
'label' => 'Created by',
'type' => 'select',
'name' => 'created_by',
'entity' => 'creator',
'label' => 'Created by',
'type' => 'select',
'name' => 'created_by',
'entity' => 'creator',
'attribute' => 'name',
]);

$this->crud->addColumn([
'label' => 'Updated by',
'type' => 'select',
'name' => 'updated_by',
'entity' => 'updater',
'label' => 'Updated by',
'type' => 'select',
'name' => 'updated_by',
'entity' => 'updater',
'attribute' => 'name',
]);
}

protected function setupShowOperation()
{
$this->setupListOperation();

$this->crud->addColumn('description');
$this->crud->addColumn('content');
}
Expand All @@ -66,32 +66,32 @@ protected function setupCreateOperation()
$this->crud->setValidation(SnippetRequest::class);

$this->crud->addField([
'type' => 'text',
'name' => 'name',
'label' => 'Name',
'type' => 'text',
'name' => 'name',
'label' => 'Name',
'wrapperAttributes' => [
'class' => 'form-group col-md-6'
]
'class' => 'form-group col-md-6',
],
]);
$this->crud->addField([
'label' => 'Category',
'type' => 'select',
'name' => 'category_id',
'entity' => 'category',
'attribute' => 'name',
'label' => 'Category',
'type' => 'select',
'name' => 'category_id',
'entity' => 'category',
'attribute' => 'name',
'wrapperAttributes' => [
'class' => 'form-group col-md-6'
]
'class' => 'form-group col-md-6',
],
]);
$this->crud->addField([
'type' => 'simplemde',
'name' => 'description',
'label' => 'Description'
'type' => 'simplemde',
'name' => 'description',
'label' => 'Description',
]);
$this->crud->addField([
'type' => 'textarea',
'name' => 'content',
'label' => 'Content'
'type' => 'textarea',
'name' => 'content',
'label' => 'Content',
]);
}

Expand Down
1 change: 0 additions & 1 deletion app/Http/Requests/CreatorRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest;

class CreatorRequest extends FormRequest
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Requests/SnippetRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest;

class SnippetRequest extends FormRequest
Expand All @@ -26,7 +25,7 @@ public function authorize()
public function rules()
{
return [
'name' => 'required|min:5|max:255',
'name' => 'required|min:5|max:255',
'category_id' => 'required',
];
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Creator extends BackpackUser
| RELATIONS
|--------------------------------------------------------------------------
*/

public function snippets()
{
return $this->hasMany('App\Models\Snippet', 'created_by');
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function category()
{
return $this->belongsTo('Backpack\NewsCRUD\app\Models\Category', 'category_id');
}

/*
|--------------------------------------------------------------------------
| SCOPES
Expand Down
12 changes: 5 additions & 7 deletions app/Models/Traits/CreatedByTrait.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?php
<?php

namespace App\Models\Traits;

use Illuminate\Database\Eloquent\Model;

trait CreatedByTrait
trait CreatedByTrait
{
/**
* Stores the user id at each create & update.
*/
public function save(array $options = [])
{
$user = backpack_auth()->check() ? backpack_auth()->user() : (\Auth::check() ? \Auth::user() : false );
$user = backpack_auth()->check() ? backpack_auth()->user() : (\Auth::check() ? \Auth::user() : false);

if ($user) {
$this->created_by = $this->created_by ?? $user->id;
Expand All @@ -26,7 +24,7 @@ public function save(array $options = [])
| RELATIONS
|--------------------------------------------------------------------------
*/

public function creator()
{
return $this->belongsTo('App\User', 'created_by');
Expand All @@ -36,4 +34,4 @@ public function updater()
{
return $this->belongsTo('App\User', 'updated_by');
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateSnippetsTable extends Migration
{
Expand Down
6 changes: 2 additions & 4 deletions routes/backpack/custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Route::crud('my-snippet', 'MySnippetCrudController');

Route::crud('creator', 'CreatorCrudController');
Route::group(['prefix' => 'creator/{user_id}'], function() {
Route::group(['prefix' => 'creator/{user_id}'], function () {
Route::crud('snippet', 'CreatorSnippetCrudController');
});

Expand All @@ -47,6 +47,4 @@
});
}
}


}); // this should be the absolute last line of this file
}); // this should be the absolute last line of this file