I have the following Model
class CountryModel extends Model
{
public $table = 'tblcountry';
public $primaryKey = 'CountryID';
public $timestamps = true;
}
Below is the Schema Builder for above Model
class TblCountry extends Migration
{
public function up()
{
Schema::create('tblCountry', function (Blueprint $table) {
$table->increments('CountryID');
$table->string('Country', 25);
$table->timestamps();
});
}
}
Below is the code that returns all countries and convert them into Json
response()->json(['Data' => \App\Models\CountryModel::all()]);
Now, Inside Controller
, I am trying to convert this JSON
into CountryModel
so that I may forward this data into View.
Question
Shall I write a Country class which will have two properties called CountryID and Country ? or there is any inbuilt method to convert the DeSerialize the JSON into Model Array?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire