Useful tips for Collection operations In Laravel

https://www.dunebook.com/useful-tips-for-collection-operations-in-laravel/
$books = AppBook::all();

if($books->contains(3))
{
return ‘yeah, book 3 is here!’;
}

$book = $books->get(2, “Not Found!”);

if($books->has(3))
{
$book = $books->get(3);
}
$book = new Book;
// other attributes assignment here…

$books->put(2, $book);

$firstBook = new Book;
// other attributes assignment here…

$books->prepend($book);

Blogbook : PHP | Javascript | Laravel | Corcel | CodeIgniter | VueJs | ReactJs | WordPress