84 lines
2.9 KiB
XML
84 lines
2.9 KiB
XML
<snippet>
|
|
<content><![CDATA[
|
|
use App\Models\\${1:Model};
|
|
use Inertia\Inertia;
|
|
|
|
public function index(Request \$request)
|
|
{
|
|
\$data = [
|
|
'all${2:Models}' => ${1:Model}::where('user_id', \$request->user()->id)->paginate(),
|
|
];
|
|
|
|
return Inertia::render('Dashboard/${2:Models}/Index')->with(\$data);
|
|
}
|
|
|
|
public function show(${1:Model} \$${4:model})
|
|
{
|
|
\$data = [
|
|
'${4:model}' => \$${4:model},
|
|
];
|
|
|
|
return Inertia::render('Dashboard/${2:Models}/Show')->with(\$data);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
\$data = [];
|
|
|
|
return Inertia::render('Dashboard/${2:Models}/Create')->with(\$data);
|
|
}
|
|
|
|
public function store(Request \$request)
|
|
{
|
|
\$${4:model} = new ${1:Model}();
|
|
// assign model fields
|
|
|
|
if (\$${4:model}->save()) {
|
|
\$request->session()->flash('flash', ['bannerStyle' => 'success', 'banner' => "Successfully added {\$${4:model}->${5:field}}."]);
|
|
return redirect()->route('dashboard.${3:models}.index')->with('status', "Successfully added {\$${4:model}->${5:field}}.");
|
|
}
|
|
|
|
\$request->session()->flash('flash', ['bannerStyle' => 'danger', 'banner' => "Unable to save that ${4:model}."]);
|
|
return redirect()->back()->with('error', 'Unable to save that ${4:model}.');
|
|
}
|
|
|
|
public function edit(Request \$request, ${1:Model} \$${4:model})
|
|
{
|
|
\$data = [
|
|
'${4:model}' => \$${4:model},
|
|
];
|
|
|
|
return Inertia::render('Dashboard/${2:Models}/Edit')->with(\$data);
|
|
}
|
|
|
|
public function update(Request \$request, ${1:Model} \$${4:model})
|
|
{
|
|
// assign model fields
|
|
|
|
if (\$${4:model}->update()) {
|
|
\$request->session()->flash('flash', ['bannerStyle' => 'success', 'banner' => "Successfully updated {\$${4:model}->${5:field}}."]);
|
|
return redirect()->route('dashboard.${3:models}.index')->with('status', "Successfully updated {\$${4:model}->${5:field}}.");
|
|
}
|
|
|
|
\$request->session()->flash('flash', ['bannerStyle' => 'danger', 'banner' => "Unable to update {\$${4:model}->${5:field}}."]);
|
|
return redirect()->back()->with('error', "Unable to update {\$${4:model}->${5:field}}.");
|
|
}
|
|
|
|
public function destroy(Request \$request, ${1:Model} \$${4:model})
|
|
{
|
|
\$${5:field} = \$${4:model}->${5:field};
|
|
if (\$${4:model}->delete()) {
|
|
\$request->session()->flash('flash', ['bannerStyle' => 'success', 'banner' => "Successfully removed {\$${5:field}}."]);
|
|
return redirect()->route('dashboard.${3:models}.index')->with('status', "Successfully removed {\$${5:field}}.");
|
|
}
|
|
|
|
\$request->session()->flash('flash', ['bannerStyle' => 'danger', 'banner' => "Unable to remove {\$${5:field}}."]);
|
|
return redirect()->back()->with('error', "Unable to remove {\$${5:field}}.");
|
|
}
|
|
]]></content>
|
|
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
|
|
<tabTrigger>laracontroller</tabTrigger>
|
|
<!-- Optional: Set a scope to limit where the snippet will trigger -->
|
|
<!-- <scope>source.python</scope> -->
|
|
</snippet>
|