1. Go to this page and download the library: Download samsin33/laravel-foundation 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/ */
samsin33 / laravel-foundation example snippets
bash
$ php artisan foundation:make-model Post
bash
use Samsin33\Foundation\Models\BaseModel;
class Post extends BaseModel
{
public function savingEvent()
{
if (parent::savingEvent()) {
// do something
return $this;
}
return false;
}
// To delete all comments if the post is deleted
public function deletedEvent()
{
Comment::where('post_id', $this->id)->delete();
}
}
bash
use Samsin33\Foundation\Models\BaseModel;
class Post extends BaseModel
{
// To delete all comments if the post is deleted
public function deletedEvent()
{
$addition_data = ['some_data'];
$this->dispatchQueue('deletePostComments', $addition_data);
}
// This function will be called once the queue is executed.
public function deletePostComments($data)
{
// $data will have $addition_data values
Comment::where('post_id', $this->id)->delete();
// To access the current user details at the time post delete() is called use $this->queue_user attribute.
$user = $this->queue_user;
}
}