PHP code example of affordablemobiles / eloquent-datastore
1. Go to this page and download the library: Download affordablemobiles/eloquent-datastore library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
affordablemobiles / eloquent-datastore example snippets
// With: protected $primaryKey = 'uuid';
// GOOD: This all works as you'd expect.
$user = User::where('uuid', 'my-uuid-string')->first();
$user = User::find('my-uuid-string');
$user = User::firstOrCreate(['uuid' => 'my-uuid-string']);
$uuid = $user->uuid;
// GOOD: This works, even if the model's $primaryKey is 'uuid'.
$user = DB::table('users')->where('id', 'my-uuid-string')->first();
// BAD: This will NOT work.
// The query builder will look for a *data property* named 'uuid',
// not the entity's key, because it is model-agnostic.
$user = DB::table('users')->where('uuid', 'my-uuid-string')->first();
class User extends Model
{
public $cacheFor = 3600; // Cache queries for 1 hour
// ...
}
// Fetch only the name
$user = User::select('name')->find(1);
$user->name = 'New Name';
// ERROR: Throws LogicException
// "Cannot save a partial model... saving it would overwrite the full entity..."
$user->save();
$user = User::find(1); // Fetches all columns
$user->name = 'New Name';
$user->save(); // OK
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.