Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Laravel 5 Essentials
  • Table Of Contents Toc
  • Feedback & Rating feedback
Laravel 5 Essentials

Laravel 5 Essentials

By : Martin Bean
3.7 (13)
close
close
Laravel 5 Essentials

Laravel 5 Essentials

3.7 (13)
By: Martin Bean

Overview of this book

This book is intended for PHP web developers who have an interest in Laravel and who know the basics of the framework in theory, but don't really know how to use it in practice. No experience of using frameworks is required, but it is assumed you are at least familiar with building dynamic websites in PHP already.
Table of Contents (10 chapters)
close
close
9
Index

Deleting data


There are two ways of deleting records. If you have a model instance that you have fetched from the database, then you can call the delete method on it:

$cat = Cat::find(1);
$cat->delete();

Alternatively, you can call the destroy method, specifying the IDs of the records you want to delete, without having to fetch those records first:

Cat::destroy(1);
Cat::destroy(1, 2, 3, 4, 5);

Soft deletion

By default, Eloquent will hard-delete records from your database. This means, once it's deleted, it's gone forever. If you need to retain deleted data (that is, for auditing), then you can use soft deletes. When deleting a model, the record is kept in the database but instead a deleted_at timestamp is set, and any records with this timestamp set will not be included when querying your database.

Soft deletes can be easily added to your Eloquent model. All you need to do is include the trait:

use Illuminate\Database\Eloquent\SoftDeletes;
class Cat extends Model {
  use SoftDeletes;
  protected...
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Laravel 5 Essentials
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon