jeudi 24 septembre 2015

Syntax to automatically generate a string on store in Laravel 5

What would be the simplest and easiest way to generate a unique string (MD5(timestamp) or UUID) automatically on an insert in Laravel 5.

This is what I have right now.

My store function

public function store(AppointmentsRequest $request)
{
    $appointment = Appointment::create(Request::all());

    return redirect('appointments/'.$appointment->id );
}

My table schema (see my_generated_string column below)

public function up()
{
    Schema::create('appointments', function(Blueprint $table)
    {
        $table->increments('id');
        $table->integer('client_id')->unsigned();
        $table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');

        $table->integer('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

        $table->dateTime('appointment_at');

        $table->string('my_generated_string')->unique(); --> Want a generated string in here

        $table->rememberToken();
        $table->timestamps();
    });
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire