質問編集履歴
3
クラス名の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
use Illuminate\Http\Request;
|
29
29
|
use App\Items;
|
30
30
|
use App\User;
|
31
|
-
use App\categor
|
31
|
+
use App\category;
|
32
32
|
use App\Http\Requests\ItemsRequest;
|
33
33
|
use App\Http\Requests\ItemsImageRequest;
|
34
34
|
//use App\Http\Requests\ProfileImageRequest;
|
2
文字数の都合でルーティング部分の記載をカット、カテゴリーモデルが抜けていた為、新しく追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,50 +18,6 @@
|
|
18
18
|
```
|
19
19
|
|
20
20
|
### 該当のソースコード
|
21
|
-
### ルーティング
|
22
|
-
```web.php
|
23
|
-
<?php
|
24
|
-
|
25
|
-
/*
|
26
|
-
|--------------------------------------------------------------------------
|
27
|
-
| Web Routes
|
28
|
-
|--------------------------------------------------------------------------
|
29
|
-
|
|
30
|
-
| Here is where you can register web routes for your application. These
|
31
|
-
| routes are loaded by the RouteServiceProvider within a group which
|
32
|
-
| contains the "web" middleware group. Now create something great!
|
33
|
-
|
|
34
|
-
*/
|
35
|
-
Auth::routes();
|
36
|
-
// トップページをログイン画面後に表示させたい場合はmiddlewareを書かないとエラーが出る
|
37
|
-
Route::get('/', function () {
|
38
|
-
return view('layouts.top');
|
39
|
-
})->middleware('auth');
|
40
|
-
// お気に入り一覧
|
41
|
-
Route::resource('likes', 'LikesController')->only([
|
42
|
-
'index', 'store', 'destroy'
|
43
|
-
]);
|
44
|
-
|
45
|
-
Route::resource('items', 'ItemsController');
|
46
|
-
|
47
|
-
Route::resource('profile', 'ProfileController')->only([
|
48
|
-
'store', 'destroy'
|
49
|
-
]);
|
50
|
-
Route::get('users/{id}/index', 'ItemsController@index')->name('users.index');
|
51
|
-
|
52
|
-
|
53
|
-
Route::get('/items/{id}/edit_image', 'ItemsController@editImage')->name('items.edit_image');
|
54
|
-
|
55
|
-
Route::patch('/items/{id}/edit_image', 'ItemsController@editImage')->name('items.update_image');
|
56
|
-
|
57
|
-
Route::get('/profile/{id}/edit', 'ProfileController@edit')->name('profile.edit');
|
58
|
-
Route::patch('/profile/{id}', 'ProfileController@update')->name('profile.update');
|
59
|
-
Route::get('/profile/{id}/edit_image', 'ProfileController@editImage')->name('profile.edit_image');
|
60
|
-
Route::patch('/profile/{id}/edit_image', 'ProfileController@updateImage')->name('profile.update_image');
|
61
|
-
|
62
|
-
Route::resource('profile', 'ProfileController')->only([
|
63
|
-
'show',
|
64
|
-
]);
|
65
21
|
```
|
66
22
|
### コントローラー
|
67
23
|
```ItemsController.php(出品関連のコントローラー)
|
@@ -357,10 +313,41 @@
|
|
357
313
|
}
|
358
314
|
|
359
315
|
```
|
316
|
+
|
317
|
+
```categories.php
|
318
|
+
<?php
|
319
|
+
|
320
|
+
namespace App;
|
321
|
+
|
322
|
+
use Illuminate\Database\Eloquent\Model;
|
323
|
+
use Illuminate\Database\Eloquent\softDeletes;
|
324
|
+
|
325
|
+
class categories extends Model
|
326
|
+
{
|
327
|
+
use SoftDeletes;
|
328
|
+
|
329
|
+
protected $primaryKey = 'category_id';
|
330
|
+
protected $fillable = ['name', 'display_order'];
|
331
|
+
protected $dates = ['deleted_at', 'created_at', 'updated_at'];
|
332
|
+
|
360
|
-
|
333
|
+
/**
|
361
|
-
|
334
|
+
* カテゴリリストを取得する
|
335
|
+
*
|
336
|
+
* @param int $num_per_page 1ページ当たりの表示件数
|
337
|
+
* @param string $order 並び順の基準となるカラム
|
338
|
+
* @param string $direction 並び順の向き asc or desc
|
339
|
+
* @return mixed
|
340
|
+
*/
|
341
|
+
public function getCategoryList(int $num_per_page = 0, string $order = 'display_order', string $direction = 'asc')
|
342
|
+
{
|
343
|
+
$query = $this->orderBy($order, $direction);
|
344
|
+
if ($num_per_page) {
|
345
|
+
return $query->paginate($num_per_page);
|
346
|
+
}
|
362
|
-
|
347
|
+
return $query->get();
|
363
|
-
|
348
|
+
}
|
349
|
+
}
|
350
|
+
|
351
|
+
```
|
364
352
|
### 補足情報(FW/ツールのバージョンなど)
|
365
|
-
|
366
353
|
Windows10 cloud9 Laravel6_v1
|
1
コントローラーに追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,6 +72,7 @@
|
|
72
72
|
use Illuminate\Http\Request;
|
73
73
|
use App\Items;
|
74
74
|
use App\User;
|
75
|
+
use App\categories;
|
75
76
|
use App\Http\Requests\ItemsRequest;
|
76
77
|
use App\Http\Requests\ItemsImageRequest;
|
77
78
|
//use App\Http\Requests\ProfileImageRequest;
|