77 lines
2.0 KiB
XML
77 lines
2.0 KiB
XML
<snippet>
|
|
<content><![CDATA[
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
public function index()
|
|
{
|
|
\$data = [
|
|
'${2:models}' => ${1:MODEL}::where('user_id', Auth::id())->paginate(),
|
|
];
|
|
|
|
return view('${2:models}.index')->with(\$data);
|
|
}
|
|
|
|
public function show(${1:MODEL} \$${3:model})
|
|
{
|
|
\$data = [
|
|
'${3:model}' => \$${3:model},
|
|
];
|
|
|
|
return view('${2:models}.show')->with(\$data);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
\$data = [];
|
|
|
|
return view('${2:models}.create')->with(\$data);
|
|
}
|
|
|
|
public function store(Request \$request)
|
|
{
|
|
\$${3:model} = new ${1:MODEL}();
|
|
// assign model fields
|
|
|
|
if (\$${3:model}->save()) {
|
|
return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully added {\$${3:model}->${4:field}}.");
|
|
}
|
|
|
|
return redirect()->back()->with('error', 'Unable to save that ${3:model}.');
|
|
}
|
|
|
|
public function edit(${1:MODEL} \$${3:model})
|
|
{
|
|
\$data = [
|
|
'${3:model}' => \$${3:model},
|
|
];
|
|
|
|
return view('${2:models}.edit')->with(\$data);
|
|
}
|
|
|
|
public function update(Request \$request, ${1:MODEL} \$${3:model})
|
|
{
|
|
// assign model fields
|
|
|
|
if (\$${3:model}->update()) {
|
|
return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully updated {\$${3:model}->${4:field}}.");
|
|
}
|
|
|
|
return redirect()->back()->with('error', "Unable to update {\$${3:model}->${4:field}}.");
|
|
}
|
|
|
|
public function destroy(${1:MODEL} \$${3:model})
|
|
{
|
|
\$${4:field} = \$${3:model}->${4:field};
|
|
if (\$${3:model}->delete()) {
|
|
return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully removed {\$${4:field}}.");
|
|
}
|
|
|
|
return redirect()->back()->with('error', "Unable to remove {\$${4: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>
|