Last active
January 10, 2023 08:45
-
-
Save uiaciel/bc19eedae034b3e53292be826cda78fa to your computer and use it in GitHub Desktop.
Model & Controller Stub Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace {{ namespace }}; | |
use {{ namespacedModel }}; | |
use {{ rootNamespace }}Http\Controllers\Controller; | |
use {{ namespacedRequests }} | |
class {{ class }} extends Controller | |
{ | |
public function index() | |
{ | |
${{ modelVariable }} = {{ model }}::All(); | |
return view('{{ modelVariable }}.index', [ | |
'{{ modelVariable }}s' => ${{ modelVariable }} | |
]); | |
} | |
public function create() | |
{ | |
return view('{{ modelVariable }}.create'); | |
} | |
public function store({{ storeRequest }} $request) | |
{ | |
{{ model }}::create($request->all()); | |
return redirect()->back()->with('success', '{{ model }} posted successfully.'); | |
} | |
public function show({{ model }} ${{ modelVariable }}) | |
{ | |
// | |
} | |
public function edit({{ model }} ${{ modelVariable }}) | |
{ | |
return view('{{ modelVariable }}.edit', compact('{{ modelVariable }}')); | |
} | |
public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }}) | |
{ | |
${{ modelVariable }}->update($request->all()); | |
return redirect()->back()->with('success', '{{ model }} updated successfully.'); | |
} | |
public function destroy({{ model }} ${{ modelVariable }}) | |
{ | |
${{ modelVariable }}->delete(); | |
return redirect()->back()->with('success', '{{ model }} deleted successfully.'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace {{ namespace }}; | |
use Illuminate\Database\Eloquent\Factories\HasFactory; | |
use Illuminate\Database\Eloquent\Model; | |
class {{ class }} extends Model | |
{ | |
use HasFactory; | |
protected $guarded = []; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment