PHP code example of kouja / project-assistant
1. Go to this page and download the library: Download kouja/project-assistant 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/ */
kouja / project-assistant example snippets
class Roynex extends BaseModel
{
use HasFactory;
protected $table = '';
protected $fillable = [];
protected $hidden = [];
protected $dates = [];
protected $casts = [];
}
trait ModelTrait
{
public function createData($data)
{
try{
$createdModel = $this::create($data);
if(empty($createdModel))
throw new CreatingModelFailException('creating data fail');
}catch(Exception $excption)
{
throw new CreatingModelFailException($excption->getMessage());
}
return $createdModel;
}
public function insertData($data)
{
try{
$insertedData = $this->insert($data);
if(empty($insertedData))
throw new InsertingDataFailException('inserting data fail');
}catch(Exception $excption)
{
throw new InsertingDataFailException($excption->getMessage());
}
return $insertedData;
}
public function updateData($filter, $newData)
{
try{
$updatedDataStatus = $this::where($filter)
->update($newData);
if(empty($updatedDataStatus))
throw new UpdatingModelFailException('updating data fail');
}catch(Exception $excption)
{
throw new UpdatingModelFailException($excption->getMessage());
}
return $updatedDataStatus;
}
public function updateOrCreateData($filter,$data)
{
try{
$queryResult = $this->updateOrCreate($filter,$data);
if(empty($queryResult))
throw new UpdatingModelFailException('deleting data fail');
}catch(Exception $excption)
{
throw new UpdatingModelFailException($excption->getMessage());
}
return $queryResult;
}
public function softDeleteData($filter)
{
try{
$deletingDataStatus = $this::where($filter)
->delete();
if(empty($deletingDataStatus))
throw new DeletingModelFailException('deleting data fail');
}catch(Exception $excption)
{
throw new DeletingModelFailException($excption->getMessage());
}
return $deletingDataStatus;
}
public function forceDeleteData($filter)
{
try{
$deletingDataStatus = $this::where($filter)
->forceDelete();
if(empty($deletingDataStatus))
throw new DeletingModelFailException('deleting data fail');
}catch(Exception $excption)
{
throw new DeletingModelFailException($excption->getMessage());
}
return $deletingDataStatus;
}
}
php artisan make:extended_model