dayjournal memo

Total 974 articles!!

Laravel #003 - コントローラを作成

Yasunori Kirimoto's avatar

画像



コントローラを作成するメモ。


コントローラ新規作成。


php artisan make:controller SampleAppController

画像



./app/Http/Controllers/


SampleAppController.php


<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SampleAppController extends Controller
{
    //
}


サンプルコード追加


SampleAppController.php


<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SampleAppController extends Controller
{

    public function index()
    {
        // サンプルを追加
        echo "サンプル";
    }

}


アクションを割り当てる


./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で表示確認。

画像



book

Q&A