I am not sure why you need all of this. Laravel has some rules which we should follow. Like table names from your no 2. https://laravel.com/docs/8.x/eloquent#table-names everything is explained in the documentation. All eloquent models are protected against mass assignment (guarded) by default. Also google for laravel best practices.
Feb 25, 2021
7
Level 4
how to test certain parameters on Model instance and its table.
I am creating a model and i want to test properties of a model like whether it
- shows and store date in specified format like in case of date and time but not limited to it.
- its table name is 'some_name',
- it has relation with other model with specified foreign keys.
- its some fields are guarded.
- some of its field are hidden.
- its primary key is some other keys like 'username' instead of 'id'
Laravel documentation doesn't provide this specifications. So is there any way i can do it. ?
Level 34
@_i.raj3sh I can make a sample unit test on your list #2 and you can do others
<?php
namespace Tests\Unit;
use Tests\TestCase;
use App\Model\MyModel; // your model for example
class MyModelTest extends TestCase
{
/** @test */
public function its_table_is_my_models()
{
$tableName = app(MyModel::class)->getTable();
$this->assertEquals($tableName, 'my_models');
}
}
I haven't tested this but just to give you an idea. You can easily do it on the other items on your list. Hope you find this useful.
Please or to participate in this conversation.