1
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 5 years have passed since last update.

PHP 文法エラーと戦ってみた 多分初心者あるある

Posted at

PHP 文法エラーと戦ってみた 多分初心者あるある

先ほど文法のエラーと戦いましたので、
載せておきます!

エラー前

Route::group(['prefix' => 'admin'], function() {
    Route::get('news/create', 'Admin\NewsController@add');

Route::group(['prefix' => 'admin'], function() {
    Route::get('admin/profile/create', 'Admin\NewsController@add');

Route::group(['prefix' => 'admin'], function() {
    Route::get('admin/profile/edit', 'Admin\NewsController@edit');

ここからエラーが発生!
なぜこうなったのか。
まずはエラーのマルポチ●にカーソルを合わせてみてエラー内容をみてみる

エラー内容

「syntax error, unexpected end of file」

ほう。
直訳すると、
「構文エラー、予期しないファイルの終わり」
と言うことは、、最後のところが何か足りない。。。

あ、カッコが足りないやんけ!!
3つのRoutingに
}}}
が足りない。。。

しかも後々気づいたけど、コードこれまとめられる!
Route::group(['prefix' => 'admin'], function() {
の中に全ての関数を入れちゃえばええんだなと察しました。

まとめてみました。

Route::group(['prefix' => 'admin'], function() {
    Route::get('news/create', 'Admin\NewsController@add');
    Route::get('admin/profile/create', 'Admin\NewsController@add');
    Route::get('admin/profile/edit', 'Admin\NewsController@edit');
}

Route::group(['prefix' => 'admin'], function() {
を2つ消したのですっきりしました!
OKと思ったが、またまたエラーです。エラーありがとう経験値溜まります。イライラも笑

エラー内容

「synatax error, unexpected end of file, expecting ','or'」

ほうほう
直訳すると
「synataxエラー、予期しないファイルの終わり、「、」が必要、または」
あ、さっきと同じようなこと言ってるなぁ
あ、
);
が足りないやんけ!!笑 何回目だよ笑
Route::group(['prefix' => 'admin'], function() {
のRoute::group()←これw
ついでに );←これもw

今度こそは思い、しっかりと付けて直しました!!

Route::group(['prefix' => 'admin'], function() {
    Route::get('news/create', 'Admin\NewsController@add');
    Route::get('admin/profile/create', 'Admin\NewsController@add');
    Route::get('admin/profile/edit', 'Admin\NewsController@edit');
});

今度はエラー出ませんでした!!!
よし!次回からは気をつけよう!!
皆さんも([]);気をつけてね٩( ᐛ )و

1
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
1
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?