A CRUD Generator Package For Laravel, Make a CRUD with no Painless !

If you found CRUDBooster Helpful, Amazing, and Awesome, please share to 1.5K Facebook 1K Twitter

Hi,


I have started using CRRUDBooster and find it very intuitive. I was able to create simple CRUDS with no problem and the end-result was excellent. However, I am unable to create a form which uses a Composite Unique Key. Here are the tables I am working with


Countries

Schema::create('countries', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});


States

Schema::create('states', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->integer('countries_id')->nullable();
$table->unique(['name','countries_id']);

$table->timestamps();
});


Whenever I tried to add a States record which is already present in the database, the system throws following error



How can I implement it through CRUDBooster so that the system pops up a message instead of this Whoops screen.


Kindly help


Aamir

User

Add comment to this question

It seems you've got a data before. Because that is MySQL regular problem message



Answered by Ferry Ariawan at Oct, 28 2017 01:41

Add comment to this answer

  • Aamir wrote at Oct, 28 2017 12:43 :

    Yes, that's a mysql problem. Is there any setting or feature in the CrudBooster which checks for a duplicate before adding the data to the table.

  • Ferry Ariawan wrote at Oct, 28 2017 15:52 :

    Ofcourse you have to check it manually via hook_before_add or hook_after_add method, you could put a validation query/ function to check it. then to redirect back, you have to use helper CRUDBooster::redirect($to,$message,$message_type='warning');

Schema::create('countries', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->softDeletes();
            $table->integer('states_id')->nullable();
            $table->string('name',25)->nullable();            
            
        });

Schema::create('states', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();


$table->timestamps();
});
country have many states,this will be the good approach of handling one many relationship



Answered by nsobi jason mwasege at Oct, 29 2017 08:44

Add comment to this answer

Answer This Question