The Seven Restful Controller Actions in Laravel

5 May 2024

Here are the 7 different RESTful actions:

  1. Create
  2. Delete
  3. Edit
  4. Index
  5. Show
  6. Store
  7. Update
And here is how you could implement them in a Laravel controller:
<?php

namespace App\Http\Controllers;

use App\Models\Post;

class PostController extends Controller
{
	public function create()
	{
		// Shows a view to create a new resource
	}

	public function destroy()
	{
		// Delete the resource
	}

	public function edit()
	{
		// Show a view to edit an existing resource
	}

	public function index()
	{
		// Render a list of a resource.
		$posts = Post::latest()->get();

		return view('post.index')
			->with('posts', $posts);
	}

	public function show($id)
	{
		// Show a single resource.
		$post = Post::findOrFail($id);

		return view('post.show')
			->with('post', $post);
	}

	public function store()
	{
		// Persist the new resource
	}

	public function update()
	{
		// Persist the edited resource
	}	
}

You might also enjoy

Useful Laravel packages

Useful Laravel packages

Published 2024-05-05

Laravel

PHP

Web development

Learn what packages that can help you build even better websites in Laravel. We'll go trhough the must-haves and packages that are just nice to have.

Read the post →
Getting title tag and meta tags from a website using PHP

Getting title tag and meta tags from a website using PHP

Published 2024-05-14

PHP

Web development

Learn how to easily webscrape title and meta tags from a website using simple PHP commands.

Read the post →
Using Linode/Akamai for your S3 storage in Laravel

Using Linode/Akamai for your S3 storage in Laravel

Published 2024-05-05

Laravel

Web development

Implementing a S3 bucket from Linode/Akamai in your Laravel application

Read the post →