Skip to content

Commit ac0d7e1

Browse files
author
Abdalrhman Emad Saad
committed
Update composer.json to deploy as a package.
1 parent 98e0891 commit ac0d7e1

37 files changed

+1067
-32
lines changed

Modules/Articles/Boots/AttachAutherIdBoot.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class AttachAutherIdBoot implements HasBooterContract
88
{
99
public function handle($model): void
1010
{
11-
dd($model);
11+
//
1212
}
13-
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
@component(layout('dashboard') . 'components.sidebarItem')
2-
@slot('url', route('dashboard.home'))
3-
@slot('name', trans('dashboard::dashboard.home'))
4-
@slot('icon', 'fas fa-layer-group')
5-
@slot('isActive', request()->routeIs('dashboard.home'))
2+
@slot('url', route('dashboard.home'))
3+
@slot('name', trans('dashboard::dashboard.home'))
4+
@slot('icon', 'fas fa-layer-group')
5+
@slot('isActive', request()->routeIs('dashboard.home'))
66
@endcomponent
77
@if (\Module::collections()->has('Accounts'))
8-
@include('accounts::sidebar')
8+
@include('accounts::sidebar')
99
@endif
1010
@if (\Module::collections()->has('Countries'))
11-
@include('countries::sidebar')
11+
@include('countries::sidebar')
1212
@endif
1313
@if (\Module::collections()->has('Articles'))
14-
@include('articles::sidebar')
14+
@include('articles::sidebar')
1515
@endif
1616
@if (\Module::collections()->has('Pages'))
17-
@include('pages::sidebar')
17+
@include('pages::sidebar')
18+
@endif
19+
@if (\Module::collections()->has('Posts'))
20+
@include('posts::sidebar')
1821
@endif
1922
@if (\Module::collections()->has('Settings'))
20-
@include('settings::sidebar')
21-
@endif
23+
@include('settings::sidebar')
24+
@endif

Modules/Posts/Config/config.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'name' => 'Posts',
5+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('posts', function (Blueprint $table) {
15+
$table->id();
16+
$table->unsignedBigInteger('user_id');
17+
$table->string('title');
18+
$table->text('content');
19+
$table->timestamps();
20+
21+
$table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*/
28+
public function down(): void
29+
{
30+
Schema::dropIfExists('posts');
31+
}
32+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Modules\Posts\Database\Seeders;
4+
5+
use Illuminate\Database\Seeder;
6+
7+
class PostsDatabaseSeeder extends Seeder
8+
{
9+
/**
10+
* Run the database seeds.
11+
*/
12+
public function run(): void
13+
{
14+
// $this->call([]);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Modules\Posts\Database\factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
class PostFactory extends Factory
8+
{
9+
/**
10+
* The name of the factory's corresponding model.
11+
*/
12+
protected $model = \Modules\Posts\Entities\Post::class;
13+
14+
/**
15+
* Define the model's default state.
16+
*/
17+
public function definition(): array
18+
{
19+
return [];
20+
}
21+
}
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Modules\Posts\Entities\Boots;
4+
5+
use Scaffolding\Booter\Contracts\HasBooterContract;
6+
7+
class AttachUserIdBooter implements HasBooterContract
8+
{
9+
public function handle(\Illuminate\Database\Eloquent\Model $model)
10+
{
11+
$model->user_id = auth()->id();
12+
}
13+
}

Modules/Posts/Entities/Post.php

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Modules\Posts\Entities;
4+
5+
use App\Http\Filters\Filterable;
6+
use Spatie\MediaLibrary\HasMedia;
7+
use Modules\Support\Traits\Selectable;
8+
use Illuminate\Database\Eloquent\Model;
9+
use Scaffolding\Booter\Traits\HasBooter;
10+
use Spatie\MediaLibrary\InteractsWithMedia;
11+
use Modules\Posts\Database\factories\PostFactory;
12+
use Modules\Posts\Entities\Boots\AttachUserIdBooter;
13+
use Illuminate\Database\Eloquent\Factories\HasFactory;
14+
use AhmedAliraqi\LaravelMediaUploader\Entities\Concerns\HasUploader;
15+
use Modules\Posts\Entities\Relations\PostRelations;
16+
17+
class Post extends Model implements HasMedia
18+
{
19+
use HasFactory,
20+
Filterable,
21+
Selectable,
22+
InteractsWithMedia,
23+
HasUploader,
24+
PostRelations,
25+
HasBooter;
26+
27+
protected $with = [
28+
'user'
29+
];
30+
31+
/**
32+
* The attributes that are mass assignable.
33+
*/
34+
protected $fillable = [
35+
'title',
36+
'content',
37+
'user_id'
38+
];
39+
40+
protected static $events = [
41+
'creating' => [
42+
AttachUserIdBooter::class
43+
]
44+
];
45+
46+
/**
47+
* The user profile image url.
48+
*
49+
* @return bool
50+
*/
51+
public function getAvatar()
52+
{
53+
return $this->getFirstMediaUrl('avatars');
54+
}
55+
56+
protected static function newFactory(): PostFactory
57+
{
58+
return PostFactory::new();
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Modules\Posts\Entities\Relations;
4+
5+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
6+
use Modules\Accounts\Entities\Customer;
7+
use Modules\Accounts\Entities\User;
8+
9+
trait PostRelations
10+
{
11+
/**
12+
* Get the user that owns the PostRelations
13+
*
14+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
15+
*/
16+
public function user(): BelongsTo
17+
{
18+
return $this->belongsTo(User::class, 'user_id');
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
namespace Modules\Posts\Http\Controllers\Dashboard;
4+
5+
use Modules\Posts\Entities\Post;
6+
use Illuminate\Contracts\View\View;
7+
use App\Http\Controllers\Controller;
8+
use Illuminate\Http\RedirectResponse;
9+
use Illuminate\Contracts\View\Factory;
10+
use Modules\Posts\Http\Requests\PostRequest;
11+
use Modules\Posts\Repositories\PostRepository;
12+
use Illuminate\Auth\Access\AuthorizationException;
13+
use Illuminate\Foundation\Validation\ValidatesRequests;
14+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
15+
16+
class PostController extends Controller
17+
{
18+
use AuthorizesRequests, ValidatesRequests;
19+
20+
/**
21+
* @var PostRepository
22+
*/
23+
protected PostRepository $repository;
24+
25+
/**
26+
* PostController constructor.
27+
* @param PostRepository $repository
28+
*/
29+
public function __construct(PostRepository $repository)
30+
{
31+
$this->middleware('permission:read_posts')->only(['index']);
32+
$this->middleware('permission:create_posts')->only(['create', 'store']);
33+
$this->middleware('permission:update_posts')->only(['edit', 'update']);
34+
$this->middleware('permission:delete_posts')->only(['destroy']);
35+
$this->middleware('permission:show_posts')->only(['show']);
36+
$this->repository = $repository;
37+
$this->repository = $repository;
38+
}
39+
40+
/**
41+
* Display a listing of the resource.
42+
* @return Factory|View
43+
*/
44+
public function index(): Factory|View
45+
{
46+
$posts = $this->repository->all();
47+
48+
return view('posts::posts.index', compact('posts'));
49+
}
50+
51+
/**
52+
* Show the form for creating a new resource.
53+
* @return Factory|View
54+
*/
55+
public function create(): Factory|View
56+
{
57+
return view('posts::posts.create');
58+
}
59+
60+
/**
61+
* Store a newly created resource in storage.
62+
* @param PostRequest $request
63+
* @return RedirectResponse
64+
*/
65+
public function store(PostRequest $request)
66+
{
67+
$post = $this->repository->create($request->all());
68+
69+
flash(trans('posts::posts.messages.created'))->success();
70+
71+
return redirect()->route('dashboard.posts.show', $post);
72+
}
73+
74+
/**
75+
* Show the specified resource.
76+
* @param Post $post
77+
* @return Factory|View
78+
* @throws AuthorizationException
79+
*/
80+
public function show(Post $post)
81+
{
82+
$post = $this->repository->find($post);
83+
84+
return view('posts::posts.show', compact('post'));
85+
}
86+
87+
/**
88+
* Show the form for editing the specified resource.
89+
* @param Post $post
90+
* @return Factory|View
91+
*/
92+
public function edit(Post $post)
93+
{
94+
return view('posts::posts.edit', compact('post'));
95+
}
96+
97+
/**
98+
* Update the specified resource in storage.
99+
* @param PostRequest $request
100+
* @param Post $post
101+
* @return RedirectResponse
102+
*/
103+
public function update(PostRequest $request, Post $post)
104+
{
105+
$post = $this->repository->update($post, $request->all());
106+
107+
flash(trans('posts::posts.messages.updated'))->success();
108+
109+
return redirect()->route('dashboard.posts.show', $post);
110+
}
111+
112+
/**
113+
* Remove the specified resource from storage.
114+
* @param Post $post
115+
* @return RedirectResponse
116+
*/
117+
public function destroy(Post $post)
118+
{
119+
$this->repository->delete($post);
120+
121+
flash(trans('posts::posts.messages.deleted'))->error();
122+
123+
return redirect()->route('dashboard.posts.index');
124+
}
125+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Modules\Posts\Http\Filters;
4+
5+
use App\Http\Filters\BaseFilters;
6+
7+
class PostFilter extends BaseFilters
8+
{
9+
//
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Modules\Posts\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class PostRequest extends FormRequest
8+
{
9+
/**
10+
* Get the validation rules that apply to the request.
11+
*/
12+
public function rules(): array
13+
{
14+
return [
15+
'title' => ['required', 'string', 'min:3', 'max:50'],
16+
'content' => ['required', 'string', 'min:1', 'max:10000']
17+
];
18+
}
19+
20+
/**
21+
* Determine if the user is authorized to make this request.
22+
*/
23+
public function authorize(): bool
24+
{
25+
return true;
26+
}
27+
}

0 commit comments

Comments
 (0)