This file contains hidden or 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 | |
| public function store() | |
| { | |
| $this->validate(request(), [ | |
| 'denaro' => [function ($attribute, $value, $fail) { | |
| if ($value <= 10) { | |
| $fail(':attribute è necessario un maggior numero'); | |
| } | |
| }] |
This file contains hidden or 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 | |
| public function store() | |
| { | |
| $this->validate(request(), [ | |
| 'denaro' => [new MiaValidationRule] | |
| ]); | |
| } |
This file contains hidden or 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 | |
| use Illuminate\Contracts\Validation\Rule; | |
| class MiaValidationRule implements Rule | |
| { | |
| public function passes($attribute, $value) | |
| { | |
| return $value > 10; | |
| } |
This file contains hidden or 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 | |
| protected $availableIncludes = [ | |
| 'actedIn', | |
| 'directed', | |
| ]; | |
| public function includeActedIn(Person $person) | |
| { | |
| $books = $person->actedIn; |
This file contains hidden or 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 | |
| protected $availableIncludes = [ | |
| 'authors', | |
| 'publishers', | |
| ]; | |
| public function includeAuthors(Book $book) | |
| { | |
| $authors = $book->authors; |
This file contains hidden or 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 | |
| Route::post('authors', 'AuthorsController@store'); | |
| // dove [$person_id => 1, $book_id => 1, 'role' => 'author'] | |
| Route::delete('authors', 'ActorsController@destroy'); | |
| Route::post('publishers', 'PublishersController@store'); | |
| // dove [$person_id => 1, $book_id => 1, 'role' => 'publisher'] | |
| Route::delete('publishers', 'PublishersController@destroy'); |
This file contains hidden or 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 | |
| Schema::create('book_person', function(Blueprint $table) { | |
| $table->unsignedInteger('person_id')->index(); | |
| $table->foreign('person_id')->references('id')->on('people'); | |
| $table->unsignedInteger('book_id')->index(); | |
| $table->foreign('book_id')->references('id')->on('books'); | |
| $table->string('role'); |
This file contains hidden or 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 | |
| Route::get('people', 'PeopleController@index'); | |
| Route::post('people', 'PeopleController@store'); | |
| Route::get('people/{person_id}', 'PeopleController@show'); | |
| Route::patch('people/{person_id}', 'PeopleController@update'); | |
| Route::delete('people/{person_id}', 'PeopleController@destroy'); |
This file contains hidden or 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 | |
| public function transform(Book $book) | |
| { | |
| return [ | |
| 'id' => $book->id, | |
| 'title' => $book->title, | |
| 'year' => $book->year, | |
| 'ranking' => $book->complicatedAlgorithmToCalculateTomatoesThumbsAndStarsForAggregateRanking(), | |
| 'links' => [ |
This file contains hidden or 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 | |
| public function index(Request $request) | |
| { | |
| $movies = Book::when($request->has('genre'), function ($query) { | |
| return $query->where('genre', $request->input('genre')); | |
| }) | |
| ->when($request->has('year'), function ($query) { | |
| return $query->where('year', $request->input('year')); | |
| }) |