Skip to content

Commit

Permalink
setting of agenda date done
Browse files Browse the repository at this point in the history
  • Loading branch information
WilsonKinyua committed Aug 12, 2021
1 parent 94aa040 commit 8d98ad1
Show file tree
Hide file tree
Showing 30 changed files with 3,300 additions and 1,570 deletions.
4 changes: 3 additions & 1 deletion app/Http/Controllers/Admin/AgendaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\AgendaDate;
use Illuminate\Http\Request;

class AgendaController extends Controller
{
// view agenda
public function index() {
return view('admin.agenda.index');
$agendaDates = AgendaDate::all();
return view('admin.agenda.index', compact('agendaDates'));
}
}
76 changes: 76 additions & 0 deletions app/Http/Controllers/Admin/AgendaDatesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\MassDestroyAgendaDateRequest;
use App\Http\Requests\StoreAgendaDateRequest;
use App\Http\Requests\UpdateAgendaDateRequest;
use App\Models\AgendaDate;
use Gate;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class AgendaDatesController extends Controller
{
public function index()
{
abort_if(Gate::denies('agenda_date_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$agendaDates = AgendaDate::all();

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

public function create()
{
abort_if(Gate::denies('agenda_date_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');

return view('admin.agendaDates.create');
}

public function store(StoreAgendaDateRequest $request)
{
$agendaDate = AgendaDate::create($request->all());

// return redirect()->route('admin.agenda-dates.index');
return redirect()->back();
}

public function edit(AgendaDate $agendaDate)
{
abort_if(Gate::denies('agenda_date_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');

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

public function update(UpdateAgendaDateRequest $request, AgendaDate $agendaDate)
{
$agendaDate->update($request->all());

return redirect()->route('admin.agenda-dates.index');
}

public function show(AgendaDate $agendaDate)
{
abort_if(Gate::denies('agenda_date_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');

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

public function destroy(AgendaDate $agendaDate)
{
abort_if(Gate::denies('agenda_date_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$agendaDate->delete();

return back();
}

public function massDestroy(MassDestroyAgendaDateRequest $request)
{
AgendaDate::whereIn('id', request('ids'))->delete();

return response(null, Response::HTTP_NO_CONTENT);
}
}
56 changes: 56 additions & 0 deletions app/Http/Controllers/Api/V1/Admin/AgendaDatesApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Http\Controllers\Api\V1\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\StoreAgendaDateRequest;
use App\Http\Requests\UpdateAgendaDateRequest;
use App\Http\Resources\Admin\AgendaDateResource;
use App\Models\AgendaDate;
use Gate;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class AgendaDatesApiController extends Controller
{
public function index()
{
abort_if(Gate::denies('agenda_date_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');

return new AgendaDateResource(AgendaDate::all());
}

public function store(StoreAgendaDateRequest $request)
{
$agendaDate = AgendaDate::create($request->all());

return (new AgendaDateResource($agendaDate))
->response()
->setStatusCode(Response::HTTP_CREATED);
}

public function show(AgendaDate $agendaDate)
{
abort_if(Gate::denies('agenda_date_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');

return new AgendaDateResource($agendaDate);
}

public function update(UpdateAgendaDateRequest $request, AgendaDate $agendaDate)
{
$agendaDate->update($request->all());

return (new AgendaDateResource($agendaDate))
->response()
->setStatusCode(Response::HTTP_ACCEPTED);
}

public function destroy(AgendaDate $agendaDate)
{
abort_if(Gate::denies('agenda_date_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');

$agendaDate->delete();

return response(null, Response::HTTP_NO_CONTENT);
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/Traits/MediaUploadingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public function storeMedia(Request $request)

$file = $request->file('file');

$name = uniqid() . '_' . trim($file->getClientOriginalName());
// $name = uniqid() . '_' . trim($file->getClientOriginalName());
$name = trim($file->getClientOriginalName());

$file->move($path, $name);

Expand Down
26 changes: 26 additions & 0 deletions app/Http/Requests/MassDestroyAgendaDateRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Requests;

use App\Models\AgendaDate;
use Gate;
use Illuminate\Foundation\Http\FormRequest;
use Symfony\Component\HttpFoundation\Response;

class MassDestroyAgendaDateRequest extends FormRequest
{
public function authorize()
{
abort_if(Gate::denies('agenda_date_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');

return true;
}

public function rules()
{
return [
'ids' => 'required|array',
'ids.*' => 'exists:agenda_dates,id',
];
}
}
26 changes: 26 additions & 0 deletions app/Http/Requests/StoreAgendaDateRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Requests;

use App\Models\AgendaDate;
use Gate;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Response;

class StoreAgendaDateRequest extends FormRequest
{
public function authorize()
{
return Gate::allows('agenda_date_create');
}

public function rules()
{
return [
'agenda_date' => [
'required',
// 'date_format:' . config('panel.date_format'),
],
];
}
}
26 changes: 26 additions & 0 deletions app/Http/Requests/UpdateAgendaDateRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Requests;

use App\Models\AgendaDate;
use Gate;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Response;

class UpdateAgendaDateRequest extends FormRequest
{
public function authorize()
{
return Gate::allows('agenda_date_edit');
}

public function rules()
{
return [
'date' => [
'required',
'date_format:' . config('panel.date_format'),
],
];
}
}
13 changes: 13 additions & 0 deletions app/Http/Resources/Admin/AgendaDateResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Resources\Admin;

use Illuminate\Http\Resources\Json\JsonResource;

class AgendaDateResource extends JsonResource
{
public function toArray($request)
{
return parent::toArray($request);
}
}
46 changes: 46 additions & 0 deletions app/Models/AgendaDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Models;

use \DateTimeInterface;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class AgendaDate extends Model
{
use SoftDeletes;
use HasFactory;

public $table = 'agenda_dates';

protected $dates = [
'agenda_date',
'created_at',
'updated_at',
'deleted_at',
];

protected $fillable = [
'agenda_date',
'created_at',
'updated_at',
'deleted_at',
];

public function getDateAttribute($value)
{
return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null;
}

public function setDateAttribute($value)
{
$this->attributes['agenda_date'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null;
}

protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

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

class CreateAgendaDatesTable extends Migration
{
public function up()
{
Schema::create('agenda_dates', function (Blueprint $table) {
$table->bigIncrements('id');
$table->date('agenda_date');
$table->timestamps();
$table->softDeletes();
});
}
}
24 changes: 24 additions & 0 deletions database/seeders/PermissionsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,32 @@ public function run()
],
[
'id' => 64,
'title' => 'agenda_date_create',
],
[
'id' => 65,
'title' => 'agenda_date_edit',
],
[
'id' => 66,
'title' => 'agenda_date_show',
],
[
'id' => 67,
'title' => 'agenda_date_delete',
],
[
'id' => 68,
'title' => 'agenda_date_access',
],
[
'id' => 69,
'title' => 'profile_password_edit',
],
[
'id' => 70,
'title' => 'no_role',
],
];

Permission::insert($permissions);
Expand Down
Loading

0 comments on commit 8d98ad1

Please sign in to comment.