Skip to content
Snippets Groups Projects
Commit 92009532 authored by PERCIN Cahit's avatar PERCIN Cahit
Browse files

exemple de modele eloquent

parent 6e963d6e
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@
"autoload":{
"psr-4": {
"ccd\\" : "src/"
"gp\\" : "src/"
}
}
}
<?php
use Illuminate\Database\Eloquent\Builder;
class Apporte extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'apporte';
protected $primaryKey = ['idCli', 'idIngre', 'idEvent'];
public $timestamps = false;
public $incrementing = false;
public function ingredient()
{
return $this->hasOne('\fridgie\modeles\Ingredient', 'idIngre');
}
}
<?php
namespace fridgie\modeles;
class Client extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'client';
protected $primaryKey = 'idCli';
public $timestamps = false ;
}
\ No newline at end of file
<?php
namespace fridgie\modeles;
use Illuminate\Database\Eloquent\Builder;
class Contient extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'contient';
protected $primaryKey = ['idRecette', 'idIngre'];
public $timestamps = false ;
public $incrementing = false;
public function recette() {
return $this->belongsTo('fridgie\modeles\Recette', 'idRecette');
}
public function ingredient() {
return $this->hasOne('fridgie\modeles\Ingredient', 'idIngre');
}
/**
* Set the keys for a save update query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function setKeysForSaveQuery(Builder $query)
{
$keys = $this->getKeyName();
if(!is_array($keys)){
return parent::setKeysForSaveQuery($query);
}
foreach($keys as $keyName){
$query->where($keyName, '=', $this->getKeyForSaveQuery($keyName));
}
return $query;
}
/**
* Get the primary key value for a save query.
*
* @param mixed $keyName
* @return mixed
*/
protected function getKeyForSaveQuery($keyName = null)
{
if(is_null($keyName)){
$keyName = $this->getKeyName();
}
if (isset($this->original[$keyName])) {
return $this->original[$keyName];
}
return $this->getAttribute($keyName);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment