![](/img/trans.png)
[英]How to fill other field in view laravel blade using select2 and laravelcollective
[英]How to fill a select using Laravel?
我是laravel的初學者,我有一個提交表單添加薪水,表薪水包含表函數的外鍵,在表單中我想用function_id填充select以選擇薪水的函數,但它給了我錯誤未定義變量:函數。
創建.blade.php
<select class="form-control" name="function_id">
<option></option>
@foreach($functions as $function)
<option value="{{ $function->id }}">{{ $function->function}}</option>
@endforeach
</select>
薪水控制器.php
<?php
namespace App\Http\Controllers;
use App\Salary;
use App\Function;
use Illuminate\Http\Request;
class SalaryController extends Controller
{
public function getFunctions(Request $request)
{
$functions = Function::get();
return view("salary.create", compact("functions"));
}
}
網頁.php
Route::get('/getFunctions','SalaryController@getFunctions');
函數.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Function extends Model
{
//
}
我只是您的控制器中的變量名稱錯誤:
class SalaryController extends Controller
{
public function getFunctions(Request $request)
{
$functions = Function::get();
// you put "fonctions"
return view("salarie.create", compact("functions"));
}
}
編輯
您在上次編輯中修復了變量名稱?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.