the Ptag controller
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use Validator;
use AppPtag;
use AppHttpResourcesPtagResource;
use IlluminateSupportFacadesAuth;
use IlluminateHttpResourcesJsonJsonResource;
use IlluminateValidationRule;
class PtagController extends Controller
{
public function index(Request $request){
$query=Ptag::query();
return PtagResource::collection($query);
}
}
ptag resource
<?php
namespace AppHttpResources;
use IlluminateHttpResourcesJsonJsonResource;
class PtagResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param IlluminateHttpRequest $request
* @return array
*/
public function toArray($request)
{
return [
'id'=>$this->id,
'title'=>$this->title
// 'product'=>$this->product()
];
}
}
ptag model
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class Ptag extends Model
{
protected $guarded=[];
public function product(){
return $this->belongsToMany('AppProduct');
}
}
error is shown as such
ErrorException: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in file /home/rajesh/project/handicom/vendor/laravel/framework/src/Illuminate/Http/Resources/DelegatesToResource.php on line 53
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…