Init(Core): add project to git and add seeders and factory
This commit is contained in:
73
app/Http/Controllers/Admin/ContentController.php
Normal file
73
app/Http/Controllers/Admin/ContentController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Models\Page;
|
||||
use App\Models\Content;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class ContentController extends Controller
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request, Page $page)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'nullable|string',
|
||||
'body' => 'required|string',
|
||||
'type' => 'in:text, image, video',
|
||||
]);
|
||||
|
||||
$content = $page->Contents()->create($validated);
|
||||
|
||||
return response(['message' => 'created', 'data' => $content]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Content $content)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Content $content)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Content $content)
|
||||
{
|
||||
//
|
||||
if($request->user_token != $content->Page->user_token){
|
||||
return response('unauthorized', 403);
|
||||
}
|
||||
$validated = $request->validate([
|
||||
'body' => 'required|string',
|
||||
]);
|
||||
|
||||
|
||||
$content->body = $validated['body'];
|
||||
$content->save();
|
||||
|
||||
return response(['message' => 'updated', 'data' => $content]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Content $content)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user