You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.8 KiB
PHTML

<?php
namespace App\Http\Controllers;
use App\Models\Info;
use Illuminate\Http\Request;
class InfoController extends Controller
{
public function index()
{
1 year ago
$query = Info::orderBy('updated_at', 'desc')->paginate();
return inertia('Info/Index', [
'query' => $query,
]);
}
1 year ago
public function create()
{
return inertia('Info/Form');
}
public function store(Request $request)
{
$request->validate([
1 year ago
'title' => 'required|string',
'description' => 'required|string',
'is_publish' => 'required|in:0,1',
]);
Info::create([
1 year ago
'title' => $request->title,
'description' => $request->description,
'is_publish' => $request->is_publish,
]);
1 year ago
return redirect()->route('info.index')
->with('message', ['type' => 'success', 'message' => 'Item has beed saved']);
}
public function edit(Info $info)
{
return inertia('Info/Form', [
'info' => $info
]);
}
public function update(Request $request, Info $info)
{
$request->validate([
1 year ago
'title' => 'required|string',
'description' => 'required|string',
'is_publish' => 'required|in:0,1',
]);
$info->update([
1 year ago
'title' => $request->title,
'description' => $request->description,
'is_publish' => $request->is_publish,
]);
1 year ago
return redirect()->route('info.index')
->with('message', ['type' => 'success', 'message' => 'Item has beed updated']);
}
public function destroy(Info $info)
{
$info->delete();
session()->flash('message', ['type' => 'success', 'message' => 'Item has beed deleted']);
}
}