How to delete Laravel cakes

Learn how to remove Laravel cookies with an example: understand the Laravel Cookie API & use it to delete cookies.

Deleting Laravel Cakes

Deleting Laravel cakes can be done in a few different ways. The most common way is to delete the cake from the database. The following example shows how to delete a cake from the database using the Laravel Eloquent ORM.


Cake::find($id)->delete();

This code will delete the cake with the specified ID. You can also delete multiple cakes at once using the Eloquent ORM.


Cake::destroy($ids);

This code will delete the cakes with the specified IDs. If you don't want to delete the cake from the database, you can also delete the cake file from the storage folder.


Storage::delete('/path/to/folder/cake.png');

This code will delete the cake file from the specified folder. You can also delete a folder and its contents.


Storage::deleteDirectory('/path/to/folder');

This code will delete the specified folder and all of its contents. You can also delete a cake from the view using the Blade templating engine.


@if (Cake::exists($id))
    {!! Form::open(['method' => 'DELETE']) !!}
        {!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
    {!! Form::close() !!}
@endif

This code will display a "Delete" button that will send an HTTP DELETE request to the server. This will delete the cake with the specified ID. You can also delete a cake using the Artisan CLI.


php artisan cake:delete $id

This code will delete the cake with the specified ID. You can also delete a cake using the Artisan migrate command.


php artisan migrate:rollback

This code will rollback the most recent migration. This will delete any changes that were made to the database. Deleting Laravel cakes is easy and can be done in multiple ways.

Answers (0)