モデルを作成するメモ。
モデル新規作成。
php artisan make:model Sample
内容はとりあえすそのまま。
./app/
Sample.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Sample extends Model
{
//
}
DBにsamplesテーブルを作成しておく。
コントローラ修正。
./app/Http/Controllers/
SampleAppController.php
<?php
namespace App\Http\Controllers;
use App\Sample;
use Illuminate\Http\Request;
class SampleAppController extends Controller
{
public function index()
{
//全レコード取得
$items = Sample::all();
return $items;
}
}
./routes/
web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('sample', 'SampleAppController@index');
localhost/sampleで表示確認。