Skip to content

Commit

Permalink
Merge pull request #100 from balajidharma/2.x-Changes
Browse files Browse the repository at this point in the history
Added attribute manager
  • Loading branch information
balajidharma authored Dec 21, 2024
2 parents fc1a640 + 0025022 commit 3365488
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 0 deletions.
112 changes: 112 additions & 0 deletions app/Http/Controllers/Admin/AttributeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use BalajiDharma\LaravelAdminCore\Actions\Attribute\AttributeCreateAction;
use BalajiDharma\LaravelAdminCore\Actions\Attribute\AttributeUpdateAction;
use BalajiDharma\LaravelAdminCore\Data\Attribute\AttributeCreateData;
use BalajiDharma\LaravelAdminCore\Data\Attribute\AttributeUpdateData;
use BalajiDharma\LaravelAdminCore\Grid\AttributeGrid;
use BalajiDharma\LaravelAttributes\Models\Attribute;

class AttributeController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\View\View
*/
public function index()
{
$this->authorize('adminViewAny', Attribute::class);
$attributes = (new Attribute)->newQuery();
$crud = (new AttributeGrid)->list($attributes);

return view('admin.crud.index', compact('crud'));
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\View\View
*/
public function create()
{
$this->authorize('adminCreate', Attribute::class);
$crud = (new AttributeGrid)->form();

return view('admin.crud.edit', compact('crud'));
}

/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function store(AttributeCreateData $data, AttributeCreateAction $attributeCreateAction)
{
$this->authorize('adminCreate', Attribute::class);
$attributeCreateAction->handle($data);

return redirect()->route('admin.attribute.index')
->with('message', 'Attribute created successfully.');
}

/**
* Display the specified resource.
*
* @return \Illuminate\View\View
*/
public function show(Attribute $attribute)
{
$this->authorize('adminView', $attribute);
$crud = (new AttributeGrid)->show($attribute);

return view('admin.crud.show', compact('crud'));
}

/**
* Show the form for editing the specified resource.
*
* @param \BalajiDharma\LaravelAttributes\Models\Attribute $attribute
* @return \Illuminate\View\View
*/
public function edit(Attribute $attribute)
{
$this->authorize('adminUpdate', $attribute);
$crud = (new AttributeGrid)->form($attribute);

return view('admin.crud.edit', compact('crud'));
}

/**
* Update the specified resource in storage.
*
* @param \BalajiDharma\LaravelAttributes\Models\Attribute $attribute
* @return \Illuminate\Http\RedirectResponse
*/
public function update(AttributeUpdateData $data, Attribute $attribute, AttributeUpdateAction $attributeUpdateAction)
{
$this->authorize('adminUpdate', $attribute);
$attributeUpdateAction->handle($data, $attribute);

return redirect()->route('admin.attribute.index')
->with('message', 'Attribute updated successfully.');
}

/**
* Remove the specified resource from storage.
*
* @param \BalajiDharma\LaravelAttributes\Models\Attribute $attribute
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Attribute $attribute)
{
$this->authorize('adminDelete', $attribute);
$attribute->delete();

return redirect()->route('admin.attribute.index')
->with('message', __('Attribute deleted successfully'));
}
}
6 changes: 6 additions & 0 deletions app/Http/Controllers/Admin/ThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use BalajiDharma\LaravelAdminCore\Data\Forum\ThreadCreateData;
use BalajiDharma\LaravelAdminCore\Data\Forum\ThreadUpdateData;
use BalajiDharma\LaravelAdminCore\Grid\ActivityLogGrid;
use BalajiDharma\LaravelAdminCore\Grid\AttributeGrid;
use BalajiDharma\LaravelAdminCore\Grid\CommentGrid;
use BalajiDharma\LaravelAdminCore\Grid\ThreadGrid;
use BalajiDharma\LaravelForum\Models\Thread;
Expand Down Expand Up @@ -76,6 +77,11 @@ public function show(Thread $thread)
'view' => 'list',
];

$relations[] = [
'crud' => (new AttributeGrid())->setRedirectUrl()->list($thread->attributes()->getQuery()),
'view' => 'list',
];

return view('admin.crud.show', compact('crud', 'relations'));
}

Expand Down
1 change: 1 addition & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AuthServiceProvider extends ServiceProvider
'Plank\Mediable\Media' => 'BalajiDharma\LaravelAdminCore\Policies\MediaPolicy',
'BalajiDharma\LaravelComment\Models\Comment' => 'BalajiDharma\LaravelAdminCore\Policies\CommentPolicy',
'BalajiDharma\LaravelForum\Models\Thread' => 'BalajiDharma\LaravelAdminCore\Policies\ThreadPolicy',
'BalajiDharma\LaravelAttributes\Models\Atrribute' => 'BalajiDharma\LaravelAdminCore\Policies\AtrributePolicy',
];

/**
Expand Down
3 changes: 3 additions & 0 deletions resources/views/admin/category/item/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<x-admin.grid.th>
{{ __('Slug') }}
</x-admin.grid.th>
<x-admin.grid.th>
{{ __('Image') }}
</x-admin.grid.th>
<x-admin.grid.th>
{{ __('Enabled') }}
</x-admin.grid.th>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?php
$media = $item->firstMedia('thumbnail');
$image = $media ?? null;
?>
<tr>
<x-admin.grid.td>
<div class="text-sm text-gray-900" style="margin-left:{{$level*20}}px;">
Expand All @@ -9,6 +13,13 @@
{{ $item['slug'] }}
</div>
</x-admin.grid.td>
<x-admin.grid.td>
<div class="w-32 rounded">
@if ($image)
<image src="{{ asset('storage/' . $image->getDiskPath()) }}" alt="{{ $image->alt }}">
@endif
</div>
</x-admin.grid.td>
<x-admin.grid.td>
<div class="text-sm text-gray-900">
{{ $item['enabled'] ? 'Enabled' : 'Disabled' }}
Expand Down
1 change: 1 addition & 0 deletions routes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
});
Route::resource('comment', 'CommentController');
Route::resource('thread', 'ThreadController');
Route::resource('attribute', 'AttributeController');
Route::get('edit-account-info', 'UserController@accountInfo')->name('account.info');
Route::post('edit-account-info', 'UserController@accountInfoStore')->name('account.info.store');
Route::post('change-password', 'UserController@changePasswordStore')->name('account.password.store');
Expand Down
1 change: 1 addition & 0 deletions routes/breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@
Breadcrumbs::resource('admin.comment', 'Comments', 'id');
Breadcrumbs::resource('admin.thread', 'Threads', 'title');
Breadcrumbs::resource('admin.activitylog', 'Activity Logs', 'id');
Breadcrumbs::resource('admin.attribute', 'Attributes', 'name');

Breadcrumbs::resource('admin.demo.forms', 'Froms');

0 comments on commit 3365488

Please sign in to comment.