Last active
May 13, 2021 10:12
-
-
Save Batisska/fc7c7847be7f335e6fcc8e14f866201c to your computer and use it in GitHub Desktop.
Updating the book.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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