Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

LaravelでMVCを利用してとりあえず表示させてみる

Last updated at Posted at 2020-10-12

【概要】

1.ルーティングの設定

2.コントローラーの設定

3.ビューの設定

4.開発環境

1.ルーティングの設定

routes/web.php
Route::get('hoge', 'App\Http\Controllers\HogeController@index' );

ここで、Route::get('hoge', 'HogeController@index' );とすると、
”Target class [HogeController] does not exist”となってしまうので、最初からパスをコーディングしました。


2.コントローラーの設定 ---------------------------------------- ```php:app/Http/Controllers/HogeControllers.php namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HogeController extends Controller
{
public function index() #---❶
{
return view('hoge.index'); #---❷
}
}

❶:ここでindexアクションを定義しています。
❷:hogeフォルダのindex.phpファイルに返り値としてレンダリングするようにしています。

<br>
3.ビューの設定
----------------------------------------

```php:resources/views/hoge/index.php
<html>
<head>
  <title>Hoge/Index</title>
</head>
<body>
  <h1>Index</h1>
  <p>HOGEHOGE</p>
</body>
</html>

簡単なHTML文しか書いていません。
「blade」テンプレートエンジンはまた後日説明します。

1~3を通じて下記が表記できます。
http://localhost:8000/hoge

スクリーンショット 2020-10-13 0.32.30.png

4.開発環境

PHP 7.4.10
Laravel 8.9.0
Apache 2.4.41

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?