大家以下是我的问题的详细信息:能够创建资源但无法检索所有资源。
RepositoryInterface
<?php
namespace Repo\Repositories\RepoInterfaces;
/**
* RepositoryInterface provides the standard functions to be expected of ANY
* repository.
*/
interface RepositoryInterface {
/**
* @param array $attributes
* @return mixed
*/
public function create(array $attributes);
/**
* @param array $columns
* @return mixed
*/
public function all($columns = array('*'));
}
抽象
<?php
namespace Repo\Abstracts;
use Repo\Repositories\RepoInterfaces\RepositoryInterface;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\DB as DB;
/**
* The Abstract Repository provides default implementations of the methods defined
* in the base repository interface. These simply delegate static function calls
* to the right eloquent model based on the $modelClassName.
*/
abstract class Repository implements RepositoryInterface {
/**
* @var
*/
protected $modelClassName;
/**
* @param array $attributes
* @return mixed
*/
public function create(array $attributes)
{
return call_user_func_array("{$this->modelClassName}::create", array($attributes));
}
/**
* @param array $columns
* @return mixed
*/
public function all($columns = array('*'))
{
return call_user_func_array("{$this->modelClassName}::all", array($columns));
}
}
VehicleManufacturerRepositoryInterface
<?php
namespace Repo\Repositories\RepoInterfaces;
/**
* The VehicleManufacturerRepositoryInterface contains ONLY method signatures for methods
* related to the VehicleManufacturer object.
*
* Note that we extend from RepositoryInterface, so any class that implements
* this interface must also provide all the standard eloquent methods (find, all, etc.)
*/
interface VehicleManufacturerRepositoryInterface extends RepositoryInterface {
}
VehicleManufacturerInterface
<?php
namespace Repo\Repositories;
use Illuminate\Support\Facades\DB as DB;
use Repo\Abstracts\Repository as AbstractRepository;
use Repo\Repositories\RepoInterfaces\VehicleManufacturerRepositoryInterface;
class VehicleManufacturerRepository extends AbstractRepository implements VehicleManufacturerRepositoryInterface
{
/**
* @var string
*/
protected $modelClassName = 'VehicleManufacturer';
}
VehicleManufacturerController
<?php
use Repo\Repositories\VehicleManufacturerRepository AS Vmanf;
class VehicleManufacturerController extends \BaseController {
public function __construct(Vmanf $vmanf)
{
$this->vmanf = $vmanf;
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$results = $this->vmanf->all(array('*'));
return Response::json(array('status'=>true,'data' => $results));
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$inputData = array (
'caption' => Input::get('caption'),
'image' => Input::get('image'),
);
if($this->vmanf->create($inputData)) {
return Response::json(array('status' => true));
} else {
return Response::json(array('status' => false,'msg' => 'Vehicle Manufacturer Not saved'));
}
}
}
结果是控制器中的商店功能可以工作但索引 函数给出以下结果{&#34; status&#34;:true,&#34; data&#34;:{}}