v1.5.13 Added crud files

This commit is contained in:
Neerholt 2021-04-22 15:31:42 +02:00
parent 9056bc6335
commit fe1cda993a
3 changed files with 205 additions and 0 deletions

View File

@ -0,0 +1,156 @@
<?php
namespace App\Http\Controllers;
use App\MultipleEvents;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
//Not in use yet
use App\Event;
use App\News;
use App\Notification;
use App\Resource;
use App\UserEvent;
class MultipleEventsController extends Controller
{
public function __construct()
{
$this->middleware([ "auth" ]);
$this->middleware([ "lang" ]);
$this->middleware([ "check.auth:event.show" ])->only("show", "index");
$this->middleware([ "check.auth:event.create" ])->only("create", "store");
$this->middleware([ "check.auth:event.edit" ])->only("edit", "update");
$this->middleware([ "check.auth:event.delete" ])->only("delete");
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$multiEvents = MultipleEvents::query()->orderBY('date' , 'asc')->get();
return Response::detect("multiple-events.index", [ "multiEvents" => $multiEvents]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//returns create multiple events blade file from the view folder
return Response::detect("multiple-events.create");
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$requestBody = $request->validate([
"week" => "max:255",
"event_name" => "array",
"accountable" => "array",
"date" => "array",
"event_name.*" => "max:255",
"accountable.*" => "max:255",
"date.*" => "max:255"
]);
for ($i = 0; $i <= 3; $i++) {
$multi_event = new MultipleEvents();
$multi_event->week = $requestBody['week'];
$multi_event->date = $requestBody['date'][$i];
$multi_event->accountable = $requestBody['accountable'][$i];
$multi_event->event_name = $requestBody['event_name'][$i];
$multi_event->save();
}
//creates a new Event model with the given parameter
$event = new Event($requestBody);
$allEvents = Event::query()->where('name', '=', $request->name)->get();
if(count($allEvents) > 0) {
return redirect()->route("events.index", ['events' => $event]);
} else {
if($request->file("resource")) {
$event->resource_id = ResourceController::store($request)->id;
}
$event->save();
$events = Event::query()->get();
if($request->newsoption == true){
$news = new News();
$news->name = "Ny ugenlig aktivitet";
$news->subname = $event->name;
$news->arrangement_id = $event->id;
$news->type_id = '3';
$news->content = $event->description;
$news->resource_id = $event->resource_id;
NewsController::storeAndGet($news);
}
return redirect()->route('events.index', ['events' => $events]);
}
}
/**
* Display the specified resource.
*
* @param \App\MultipleEvents $multipleeventsController
* @return \Illuminate\Http\Response
*/
public function show(MultipleeventsController $multipleeventsController)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\MultipleEvents $multipleeventsController
* @return \Illuminate\Http\Response
*/
public function edit(MultipleeventsController $multipleeventsController)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\MultipleEvents $multipleeventsController
* @return \Illuminate\Http\Response
*/
public function update(Request $request, MultipleeventsController $multipleeventsController)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\MultipleEvents $multipleeventsController
* @return \Illuminate\Http\Response
*/
public function destroy(MultipleeventsController $multipleeventsController)
{
//
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class MultipleEvents extends Model
{
protected $fillable = [
'date', 'event_name', 'accountable', 'week'
];
}

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMultipleEvents extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('multiple_events', function (Blueprint $table) {
$table->id();
$table->string('week');
$table->json('date');
$table->json('event_name');
$table->json('accountable');
//$table->longText('event_name');
//$table->string('accountable');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('multipleevents_controllers');
}
}