質問編集履歴
1
初心者マーク
test
CHANGED
File without changes
|
test
CHANGED
@@ -189,3 +189,157 @@
|
|
189
189
|
|
190
190
|
|
191
191
|
よろしくおながいします。
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
追記
|
196
|
+
|
197
|
+
```controller
|
198
|
+
|
199
|
+
use Illuminate\Http\Request;
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
use App\Facades\Calendar;
|
204
|
+
|
205
|
+
use App\Services\CalendarService;
|
206
|
+
|
207
|
+
use App\Skiday;
|
208
|
+
|
209
|
+
use App\Http\Requests\CreateSkidayRequest;
|
210
|
+
|
211
|
+
use Illuminate\Support\Facades\Auth;
|
212
|
+
|
213
|
+
public function postSkiday(CreateSkidayRequest $request)
|
214
|
+
|
215
|
+
{
|
216
|
+
|
217
|
+
// dd($request);
|
218
|
+
|
219
|
+
$user = Auth::user();
|
220
|
+
|
221
|
+
$skiday = new Skiday();
|
222
|
+
|
223
|
+
$skiday->user_id = $user->id;
|
224
|
+
|
225
|
+
$skiday->day = $request->day;
|
226
|
+
|
227
|
+
$skiday->number_of_people = $request->number_of_people;
|
228
|
+
|
229
|
+
$skiday->ski_area = $request->ski_area;
|
230
|
+
|
231
|
+
$skiday->category = $request->category;
|
232
|
+
|
233
|
+
$skiday->time_zone = $request->time_zone;
|
234
|
+
|
235
|
+
$skiday->info = $request->info;
|
236
|
+
|
237
|
+
$skiday->save();
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
return redirect()->route('calendar.show', ['skiday' => $skiday,]);
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
```
|
246
|
+
|
247
|
+
```Request
|
248
|
+
|
249
|
+
use App\Enums\NumberState;
|
250
|
+
|
251
|
+
use Illuminate\Foundation\Http\FormRequest;
|
252
|
+
|
253
|
+
use BenSampo\Enum\Rules\EnumKey;
|
254
|
+
|
255
|
+
public function rules()
|
256
|
+
|
257
|
+
{
|
258
|
+
|
259
|
+
return [
|
260
|
+
|
261
|
+
'day' => 'required|date|after::"now"',
|
262
|
+
|
263
|
+
'number_of_people' => 'required',
|
264
|
+
|
265
|
+
'ski_area' => 'required',
|
266
|
+
|
267
|
+
'category' => ['required', new EnumKey(NumberState::class)],
|
268
|
+
|
269
|
+
'time_zone' => 'required',
|
270
|
+
|
271
|
+
'info' => 'nullable',
|
272
|
+
|
273
|
+
];
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
public function attributes()
|
280
|
+
|
281
|
+
{
|
282
|
+
|
283
|
+
return [
|
284
|
+
|
285
|
+
'day' => '日程',
|
286
|
+
|
287
|
+
'number_of_people' => '人数',
|
288
|
+
|
289
|
+
'ski_area' => '場所(スキー場、山)',
|
290
|
+
|
291
|
+
'category' => 'カテゴリー',
|
292
|
+
|
293
|
+
'time_zone' => '時間帯',
|
294
|
+
|
295
|
+
'info' => 'メモ',
|
296
|
+
|
297
|
+
];
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
```
|
302
|
+
|
303
|
+
```web
|
304
|
+
|
305
|
+
Route::get('/calendar/creat', 'CalendarController@getSkiday');
|
306
|
+
|
307
|
+
Route::post('/calendar/creat', 'CalendarController@postSkiday');
|
308
|
+
|
309
|
+
```
|
310
|
+
|
311
|
+
```migration
|
312
|
+
|
313
|
+
public function up()
|
314
|
+
|
315
|
+
{
|
316
|
+
|
317
|
+
Schema::create('skidays', function (Blueprint $table) {
|
318
|
+
|
319
|
+
$table->bigIncrements('id');
|
320
|
+
|
321
|
+
$table->bigInteger('user_id')->unsigned();
|
322
|
+
|
323
|
+
$table->date('day');
|
324
|
+
|
325
|
+
$table->enum('number_of_people', NumberState::getValues());
|
326
|
+
|
327
|
+
$table->string('ski_area');
|
328
|
+
|
329
|
+
$table->string('category');
|
330
|
+
|
331
|
+
$table->string('time_zone');
|
332
|
+
|
333
|
+
$table->text('info')->nullable();
|
334
|
+
|
335
|
+
$table->timestamps();
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
340
|
+
|
341
|
+
});
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
```
|