logo
We provide creative solutions in form of web and mobile applications to clients around the world, creating apps that get attention and meaningful.

Web Development

Mobile Applications Development

Business Solutions

Odoo ERP Implementation

Wordpress Plugins

WordPress Themes

Laravel Development

Server Security

Server Administration

Mobile Marketing

Pay Per Click (PPC) Management

Conversion Rate Optimization

Email Marketing

Online Presence Analysis

Fell Free To contact Us
We are available from Monday to Friday 9AM to 6PM.

+92-323-5531561

talk@appknitters.com

Lahore, Punjab, Pakistan

+92-323-5531561

Lahore, Punjab, Pakistan

Top

Laravel Eloquent: A or B methods

Eloquent has some functions that combine two methods, like “please do this, otherwise do that”.

findOrFail():

If you want to do one task otherwise another then do it like this:

$record = Record::findOrFail($id);

Instead of:

$record = Record::find($id);
if (!$record) { abort (404); }

firstOrCreate():

If you want to create a record but only if it does not exist already in database, then do it like this:

$record = Record::firstOrCreate(['name' => $name]);

Instead of:

$record = Record::where('name', $name)->first();

if (!record) { Record::create([ 'name' => $name ]);}

Having more than six years of experince developing custom applications with Laravel, WordPress, Zend, and Cordova.

No Comments

Post a Comment