Skip to content

Instantly share code, notes, and snippets.

@elinardo10
Last active June 5, 2019 03:00
Show Gist options
  • Save elinardo10/914179f0a87aad96ba5504774bd388a1 to your computer and use it in GitHub Desktop.
Save elinardo10/914179f0a87aad96ba5504774bd388a1 to your computer and use it in GitHub Desktop.
<?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);
}
}
<?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);
}
}
<?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