1. Go to this page and download the library: Download jeidison/composite-key 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/ */
jeidison / composite-key example snippets
namespace App;
use Illuminate\Database\Eloquent\Model;
class MyClass extends Model
{
use Jeidison\CompositeKey\CompositeKey;
...
}
public function index()
{
$modelX = ModelX::find(1);
// or
$modelX = ModelX::find(['c1' => 1, 'c2' => 2]);
}
public function index()
{
$modelX = ModelX::findOrFail(1);
// or
$modelX = ModelX::findOrFail(['c1' => 1, 'c2' => 2]);
}
public function index()
{
$modelX = ModelX::findMany([['c1' => 1, 'c2' => 2]]);
// or
$modelX = ModelX::findMany([['c1' => 1, 'c2' => 2], ['a1' => 1, 'a2' => 2]]);
}
public function index()
{
$modelX = ModelX::find(1);
$freshModelX = $modelX->fresh();
}
public function index()
{
$anyWhatever = Anything::find(1);
$freshAnyWhatever = $anyWhatever->refresh();
}
public function index()
{
$modelX = ModelX::find(1);
$modelX->delete();
}
public function index()
{
$count = ModelX::destroy(['c1' => 1, 'c2' => 2]);
// or
$count = ModelX::destroy([['c1' => 1, 'c2' => 2], ['a1' => 1, 'a2' => 2]]);
}