Last active
June 5, 2019 03:00
-
-
Save elinardo10/914179f0a87aad96ba5504774bd388a1 to your computer and use it in GitHub Desktop.
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\Acme\Controllers; | |
use App\Acme\Requests\HotelStoreRequest; | |
use App\Http\Controllers\Controller; | |
use App\Acme\Services\HotelService; | |
class HotelsController extends Controller | |
{ | |
private $hotelService; | |
public function __construct(HotelService $hotelService) | |
{ | |
$this->middleware('auth:api'); | |
$this->hotelService = $hotelService; | |
} | |
public function store(HotelStoreRequest $request) | |
{ | |
$input = $request->getInput(); | |
return $this->hotelService->saveHotel($input); | |
} | |
} |
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\Acme\Services; | |
use App\Acme\Models\Hotel; | |
use App\Acme\Resources\HotelResource; | |
use App\Acme\Traits\ApiResponseTrait; | |
class HotelService | |
{ | |
use ApiResponseTrait; | |
public function saveHotel($input) | |
{ | |
$hotels = Hotel::create([ | |
'title' => $input['title'], | |
//'slug' => str_slug($input['title'], '-'), | |
'address' => $input['address'], | |
'description' => $input['description'], | |
'language_id' => $input['language_id'], | |
'city_id' => $input['city_id'], | |
//'cover' => $imagem_nome, | |
]); | |
// $hotels = Hotel::create($input); | |
return new HotelResource($hotels); | |
} | |
} |
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\Acme\Requests; | |
class HotelStoreRequest extends ApiRequest | |
{ | |
/** | |
* Determine if the user is authorized to make this request. | |
* | |
* @return bool | |
*/ | |
public function authorize() | |
{ | |
return true; | |
} | |
/** | |
* Get the validation rules that apply to the request. | |
* | |
* @return array | |
*/ | |
public function rules() | |
{ | |
return [ | |
'title' => 'required|string', | |
'address' => 'required|string', | |
'description' => 'string|nullable', | |
'cover' => 'string|nullable', | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment