我需要在Laravel4中获取关于Costumers的id和Name to DropDown,在Laravel4中我使用以下代码。
public function create()
{
$data = ['groups' => Cliente::lists('name', 'id')];
return view('projects.create')->with('data',$data);
}
之后,在我使用以下
显示的视图中{{ Form::select('group', $groups) }}
但是在控制器客户端我有这个
<?php namespace App\Http\Controllers;
use App\Project;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Input;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
class ClienteController extends Controller {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$projects = Cliente::all();
return $projects;
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
}
当我执行视图创建时,我可以看到以下错误
Class 'App\Http\Controllers\Cliente' not found
最后我使用了这个但是我需要在视图中显示客户端的名称和id,不仅仅是id,还有任何解决方案吗?
public function create()
{
$data = ['Selecciona el ID del ususario' => \DB::table('clientes')->lists('id','id')];
return view('projects.create')->with('groups',$data);
然后,视图。
{!! Form :: select('user_id',$ groups)!!}