PHP code example of snowpenguinstudios / laravel-model-status
1. Go to this page and download the library: Download snowpenguinstudios/laravel-model-status 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/ */
snowpenguinstudios / laravel-model-status example snippets
return [
];
Schema::table('table-name', function (Blueprint $table) {
$table->foreignId('status_id');
});
use SnowPenguinStudios\LaravelModelStatus\Traits\HasStatus;
class ModelName extends Model {
use HasStatus;
...
}
use SnowPenguinStudios\LaravelModelStatus\Models\Status;
$status = Status::create([
'name' => 'New',
'is_active' => true
]);
use SnowPenguinStudios\LaravelModelStatus\Models\Status;
$status = Status::create([
'name' => 'New',
'model' => ModelName::class,
'is_active' => true
]);
...
$model->status_id = $status->id;
...
$model->save();
// This will work for create() as well...
$model->update([
...
'status_id' => $status->id,
...
]);
$availableStatuses = DataModdel::availableStatuses();
$defaultStatus = DataModdel::defaultStatus();
$orderedStatuses = Status::order()->get();
$orderedStatuses = Status::order('asc')->get();
$orderedStatuses = Status::order('desc')->get();
$orderedStatuses = Status::where('model', DataModel::class)->order()->get();
$orderedAscStatuses = DataModel::availableStatuses('asc');
$orderedDescStatuses = DataModel::availableStatuses('desc');
$model->status;
// Returns the status model object
$model->status_updates;
// Returns a Collection of status update model
$model->latestStatusUpdate();
// Returns the latest, in sequence, status update model object.
bash
php artisan vendor:publish --provider="SnowPenguinStudios\LaravelModelStatus\LaravelModelStatusServiceProvider" --tag="laravel-model-status-migrations"
php artisan migrate