class ManagementRequest extends FormRequest
{
/**
* 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 [
'name' => 'required|string',
'address' => 'required|string',
'phone' => 'required|digits:11',
'num' => 'required|numeric|digits_between:1,2',
'days' => 'required|numeric|digits_between:1,4',
'start_day' => 'required|date',
];
}
}
use App\Http\Requests\ManagementRequest;
/**
* 登録処理
*/
public function store(ManagementRequest $request)
/**
* 更新処理
*/
public function update(ManagementRequest $request)
class ReserveManagement extends Model
{
protected $table = 'reserve_managements';
public function reserveDayLists()
{
return $this->belongsToMany('App\Model\ReserveDayList');
}
}
class ReserveDayList extends Model
{
protected $table = 'reserve_day_lists';
public function reserveManagements()
{
return $this->belongsToMany('App\Model\ReserveManagement');
}
}
これで、各モデルから連携先のモデルを直接参照することができます。
最後にリポジトリの修正を行います。
public function add($param)
{
$model = new ReserveManagement;
foreach($this->paramNames as $name)
{
$model->$name = $param[$name];
}
$model->save();
$model2 = new ReserveDayList();
$model2->day = $model->start_day;
$model2->save();
$model->reserveDayLists()->attach($model2);
for($i = 1; $i < $model->days; $i++)
{
$model2 = new ReserveDayList();
$model2->day = date('Y-m-d', strtotime($model->start_day.'+'.$i.' day'));
$model2->save();
$model->reserveDayLists()->attach($model2);
}
}
taki@taki-300-030jp:~/minecraft-server$ java -Xmx1024M -Xms1024M -jar server.jar nogui
[20:01:20] [main/ERROR]: Failed to load properties from file: server.properties
[20:01:20] [main/WARN]: Failed to load eula.txt
[20:01:20] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
<?php
namespace App\Repository;
use App\Model\ReserveManagement;
class RegisterManagementRepository
{
// 予約一覧を取得する
public function getList()
{
return ReserveManagement::all();
}
}
今回はリスト取得だけの機能だけ実装します。
これをコントローラーで使用します。
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Repository\RegisterManagementRepository;
class RegisterManagementController extends Controller
{
protected $registerManagement;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->registerManagement = new RegisterManagementRepository();
}
/**
* Show the Register.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('register.index', ['registerLists' => $this->registerManagement->getList()]);
}
}