I have attached my semester migration code and semester seeder code. Kindly tell me if you need any other pictures for guidance.
when I send data through seeders It only takes the numbers but not the string, because it creates an integer column in the database, Help me someone who knows about laravel migrations.
At the end, you can also see the database table of seemster.
[
CodePudding user response:
From Docs:
The foreignIdFor method adds a {column}_id UNSIGNED BIGINT equivalent column for a given model class
Which basically means, it is creating BIGINT
column in database not char
like uuid.
It is better to use:
$table->foreignUuid('degreeId');
in migration.
CodePudding user response:
I would suggest revisiting your approach of using UUID. I believe you have missed some steps on your way while implementing UUID.
Add this to Semester Model
public $incrementing = false;
Create a trait
namespace App;
use Illuminate\Support\Str;
trait Uuids
{
/**
* Boot function from laravel.
*/
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->{$model->getKeyName()} = Str::uuid()->toString();
});
}
}
Use this trait in the semester Model
Follow this brilliant article from medium and if the problem persists post it here again to ask your questions
https://medium.com/@steveazz/setting-up-uuids-in-laravel-5-552412db2088