Skip to content

Instantly share code, notes, and snippets.

@Batisska
Last active May 13, 2021 10:12
Show Gist options
  • Save Batisska/fc7c7847be7f335e6fcc8e14f866201c to your computer and use it in GitHub Desktop.
Save Batisska/fc7c7847be7f335e6fcc8e14f866201c to your computer and use it in GitHub Desktop.
Updating the book.
<?php
namespace App\Domains\Book\Jobs;
use App\Data\Models\Book;
use Lucid\Units\Job;
class UpdateBookJob extends Job
{
/**
* @var string
*/
private string $title;
/**
* @var string
*/
private string $description;
/**
* @var int
*/
private int $book_id;
/**
* Create a new job instance.
*
* @param int $book_id
* @param string $title
* @param string $description
*/
public function __construct(int $book_id,string $title, string $description)
{
$this->title = $title;
$this->description = $description;
$this->book_id = $book_id;
}
/**
* Execute the job.
*
* @param Book $book
* @return mixed
*/
public function handle(Book $book): mixed
{
$book->where('id',$this->book_id)->update([
'title' => $this->title,
'description' => $this->description,
]);
return $book->where('id',$this->book_id)->with('authors')->first();;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment