-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
305 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Accounts; | ||
|
||
use App\Models\Blog; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
|
||
class BlogController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
$data['blogs'] = Blog::all(); | ||
return view('accounts.blogs.index', $data); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function create() | ||
{ | ||
return view('accounts.blogs.create'); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$request->validate([ | ||
'image' => ['required', 'file', 'image'], | ||
'title' => ['required', 'string', 'max:255'], | ||
'body' => ['required', 'string'], | ||
]); | ||
|
||
/** | ||
* @var \App\Models\Blog $blog | ||
*/ | ||
$blog = Blog::create($request->except('image')); | ||
|
||
$blog->uploadFromRequest('image')->save(); | ||
|
||
return redirect(route('accounts.blogs.index')); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param \App\Models\Blog $blog | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show(Blog $blog) | ||
{ | ||
$data['blog'] = $blog; | ||
return view('accounts.blogs.show', $data); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param \App\Models\Blog $blog | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit(Blog $blog) | ||
{ | ||
$data['blog'] = $blog; | ||
return view('accounts.blogs.edit', $data); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \App\Models\Blog $blog | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request, Blog $blog) | ||
{ | ||
$request->validate([ | ||
// | ||
]); | ||
|
||
$blog->update([ | ||
// | ||
]); | ||
|
||
return redirect(route('accounts.blogs.index')); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param \App\Models\Blog $blog | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy(Blog $blog) | ||
{ | ||
$blog->delete(); | ||
return back(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
app/Http/Controllers/RoleController.php → ...p/Controllers/Accounts/RoleController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Plusemon\Uploader\traits\HasUploader; | ||
|
||
class Blog extends Model | ||
{ | ||
use HasFactory, HasUploader; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = ['image', 'title', 'body']; | ||
} |
34 changes: 34 additions & 0 deletions
34
database/migrations/2022_06_01_223654_create_blogs_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('blogs', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('image')->nullable(); | ||
$table->string('title'); | ||
$table->longText('body'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('blogs'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@extends('accounts.layouts.main', $meta) | ||
|
||
@php | ||
$meta['title'] = 'Add New Blog'; | ||
@endphp | ||
|
||
@section('main') | ||
<main class="page-content"> | ||
<div class="card"> | ||
<div class="card-header d-flex justify-content-between"> | ||
<h5>{{ $meta['title'] }}</h5> | ||
</div> | ||
<div class="card-body"> | ||
@include('components.errors') | ||
<form action="{{ route('accounts.blogs.store') }}" method="POST" enctype="multipart/form-data" | ||
class="row col-md-10 m-auto border p-3"> | ||
@csrf | ||
<div class="mb-3"> | ||
<label for="">Image</label> | ||
<input type="file" name="image" class="form-control-file"> | ||
</div> | ||
<div class="mb-1"> | ||
<label for="">Title</label> | ||
<input type="text" name="title" value="{{ old('title') }}" class="form-control"> | ||
</div> | ||
<div class="mb-1"> | ||
<label for="">Body / Description</label> | ||
<textarea name="body" class="form-control" cols="30" rows="10">{{ old('body') }}</textarea> | ||
</div> | ||
<div class="mt-3 text-center"> | ||
<button class="btn btn-primary">Save</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</main> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@extends('accounts.layouts.main', $meta) | ||
|
||
@php | ||
$meta['title'] = 'Blogs'; | ||
@endphp | ||
|
||
@section('main') | ||
<main class="page-content"> | ||
<div class="card"> | ||
<div class="card-header d-flex justify-content-between"> | ||
<h5>{{ $meta['title'] }}</h5> | ||
<a href="{{ route('accounts.blogs.create') }}" class="btn btn-sm btn-primary">Add New</a> | ||
</div> | ||
<div class="card-body"> | ||
<div class="table-responsive"> | ||
<table class="table table-striped table-bordered datatable"> | ||
<thead> | ||
<tr> | ||
<th>#</th> | ||
<th>Image</th> | ||
<th>Title</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach ($blogs as $blog) | ||
<tr> | ||
<td>{{ $loop->iteration }}</td> | ||
<td><img src="{{ $blog->urlOf('image') }}" height="70"></td> | ||
<td>{{ $blog->title }}</td> | ||
|
||
<td class="text-center"> | ||
<form action="{{ route('accounts.blogs.destroy', $blog) }}" | ||
onsubmit="return confirm('are you sure want to delete this item?')" method="POST"> | ||
@csrf | ||
@method('delete') | ||
<div class="btn-group"> | ||
<button type="button" class="btn btn-sm btn-outline-primary">Edit</button> | ||
<button type="submit" class="btn btn-sm btn-outline-danger">Delete</button> | ||
</div> | ||
</form> | ||
</td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
@endsection |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.