updated various snippets

This commit is contained in:
2022-06-14 12:46:10 -06:00
parent 1bc953bc44
commit e27b91fc14
6 changed files with 64 additions and 47 deletions

View File

@ -1,14 +1,15 @@
<snippet>
<content><![CDATA[
use Illuminate\Support\Facades\Auth;
use App\Models\${1:MODEL};
use Inertia\Inertia;
public function index()
public function index(Request \$request)
{
\$data = [
'${2:models}' => ${1:MODEL}::where('user_id', Auth::id())->paginate(),
'${2:models}' => ${1:MODEL}::where('user_id', \$request->user()->id)->paginate(),
];
return view('${2:models}.index')->with(\$data);
return Inertia::render('${2:models}/Index')->with(\$data);
}
public function show(${1:MODEL} \$${3:model})
@ -17,14 +18,14 @@ public function show(${1:MODEL} \$${3:model})
'${3:model}' => \$${3:model},
];
return view('${2:models}.show')->with(\$data);
return Inertia::render('${2:models}/Show')->with(\$data);
}
public function create()
{
\$data = [];
return view('${2:models}.create')->with(\$data);
return Inertia::render('${2:models}/Create')->with(\$data);
}
public function store(Request \$request)
@ -33,21 +34,21 @@ public function store(Request \$request)
// assign model fields
if (\$${3:model}->save()) {
\$request->session()->flash('status', "Successfully added {\$${3:model}->${4:field}}.");
\$request->session()->flash('flash', ['bannerStyle' => 'success', 'banner' => "Successfully added {\$${3:model}->${4:field}}."]);
return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully added {\$${3:model}->${4:field}}.");
}
\$request->session()->flash('error', 'Unable to save that ${3:model}.');
\$request->session()->flash('flash', ['bannerStyle' => 'danger', 'banner' => "Unable to save that ${3:model}."]);
return redirect()->back()->with('error', 'Unable to save that ${3:model}.');
}
public function edit(${1:MODEL} \$${3:model})
public function edit(Request \$request, ${1:MODEL} \$${3:model})
{
\$data = [
'${3:model}' => \$${3:model},
];
return view('${2:models}.edit')->with(\$data);
return Inertia::render('${2:models}/Edit')->with(\$data);
}
public function update(Request \$request, ${1:MODEL} \$${3:model})
@ -55,11 +56,11 @@ public function update(Request \$request, ${1:MODEL} \$${3:model})
// assign model fields
if (\$${3:model}->update()) {
\$request->session()->flash('status', "Successfully updated {\$${3:model}->${4:field}}.");
\$request->session()->flash('flash', ['bannerStyle' => 'success', 'banner' => "Successfully updated {\$${3:model}->${4:field}}."]);
return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully updated {\$${3:model}->${4:field}}.");
}
\$request->session()->flash('error', "Unable to update {\$${3:model}->${4:field}}.");
\$request->session()->flash('flash', ['bannerStyle' => 'danger', 'banner' => "Unable to update ${3:model}."]);
return redirect()->back()->with('error', "Unable to update {\$${3:model}->${4:field}}.");
}
@ -67,11 +68,11 @@ public function destroy(Request \$request, ${1:MODEL} \$${3:model})
{
\$${4:field} = \$${3:model}->${4:field};
if (\$${3:model}->delete()) {
\$request->session()->flash('status', "Successfully removed {\$${4:field}}.");
\$request->session()->flash('flash', ['bannerStyle' => 'success', 'banner' => "Successfully removed {\$${4:field}}."]);
return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully removed {\$${4:field}}.");
}
\$request->session()->flash('error', "Unable to remove {\$${4:field}}.");
\$request->session()->flash('flash', ['bannerStyle' => 'danger', 'banner' => "Unable to remove {\$${4:field}}."]);
return redirect()->back()->with('error', "Unable to remove {\$${4:field}}.");
}
]]></content>