前提・実現したいこと
bladephp
1$rules = ['0'=>'stop', '1'=>'run', '2'=>'turn'] 2 3@switch($signal) 4 @foreach ($rules as $rule) 5 @case($rule->key) 6 {{ $rule[$key] }} 7 @break 8 @endforeach 9 @default 10@endswitch 11
このようにseitch文の中でforeach文を記述して、$ruleの定義に対して動的に制御構文を作ろうとしたところで以下のエラーが出ました
もしかしてこのような記述はbladeではできないのでしょうか
そもそもviewで書かずにcontrollerで書くべきやるべきだ、などのアドバイスも含めてよろしくお願いします
発生している問題・エラーメッセージ
ParseError syntax error, unexpected '<', expecting endswitch (T_ENDSWITCH) or case (T_CASE) or default (T_DEFAULT)
補足情報(FW/ツールのバージョンなど)
% sw_vers ProductName: Mac OS X ProductVersion: 10.15.7 BuildVersion: 19H2 % docker version Client: Docker Engine - Community Cloud integration: 1.0.1 Version: 19.03.13 API version: 1.40 # php -v PHP 7.4.7 (cli) (built: Jun 11 2020 18:41:17) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans # php artisan -v Laravel Framework 7.26.1 # mysql --version mysql Ver 14.14 Distrib 5.7.30, for Linux (x86_64) using EditLine wrapper
composerjson
1{ 2 "name": "laravel/laravel", 3 "type": "project", 4 "description": "The Laravel Framework.", 5 "keywords": [ 6 "framework", 7 "laravel" 8 ], 9 "license": "MIT", 10 "require": { 11 "php": "^7.2.5", 12 "bensampo/laravel-enum": "2", 13 "encore/laravel-admin": "^1.8", 14 "fideloper/proxy": "^4.2", 15 "fruitcake/laravel-cors": "^2.0", 16 "guzzlehttp/guzzle": "^6.3", 17 "intervention/image": "^2.5", 18 "kalnoy/nestedset": "^5.0", 19 "laravel/framework": "^7.24", 20 "laravel/tinker": "^2.0", 21 "laravel/ui": "^2.2", 22 "spatie/eloquent-sortable": "^3.9" 23 }, 24 "require-dev": { 25 "facade/ignition": "^2.0", 26 "fzaninotto/faker": "^1.9.1", 27 "mockery/mockery": "^1.3.1", 28 "nunomaduro/collision": "^4.1", 29 "oscarafdev/migrations-generator": "^2.0", 30 "phpunit/phpunit": "^8.5" 31 }, 32 "config": { 33 "optimize-autoloader": true, 34 "preferred-install": "dist", 35 "sort-packages": true 36 }, 37 "extra": { 38 "laravel": { 39 "dont-discover": [] 40 } 41 }, 42 "autoload": { 43 "psr-4": { 44 "App\": "app/" 45 }, 46 "classmap": [ 47 "database/seeds", 48 "database/factories" 49 ] 50 }, 51 "autoload-dev": { 52 "psr-4": { 53 "Tests\": "tests/" 54 } 55 }, 56 "minimum-stability": "dev", 57 "prefer-stable": true, 58 "scripts": { 59 "post-autoload-dump": [ 60 "Illuminate\Foundation\ComposerScripts::postAutoloadDump", 61 "@php artisan package:discover --ansi" 62 ], 63 "post-root-package-install": [ 64 "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 65 ], 66 "post-create-project-cmd": [ 67 "@php artisan key:generate --ansi" 68 ] 69 } 70}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。