Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUID not filled on save() #12

Closed
emp-sean opened this issue Nov 10, 2017 · 2 comments
Closed

UUID not filled on save() #12

emp-sean opened this issue Nov 10, 2017 · 2 comments

Comments

@emp-sean
Copy link

Attempting to use this, but when saving no UUID is entered into the db.

Here is my setup:

DB:
Name: uuid char(36) utf8mb4_unicode_ci

Account Model:

use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
use Emadadly\LaravelUuid\Uuids;

class Account extends Model
{
   use Uuids;

Controller:

`public function saveUUID(Account $account){

	$example = new Account;

	$example->name = 'test';
	$example->short = 'FIVE';
	$example->industry_id = 1;
	$example->user_id = 1;
	$example->status_id = 36;
	$example->save();

return response()->json(['example' => $example]);

}`

The uuid field is left null, and the response for $example does not include the uuid.

What am i missing or doing wrong?

@EmadAdly
Copy link
Owner

@empsean i'm sorry for delay really i'm very busy, so I make a similar example and it works without any problem
please check your code with the below lines.

db Schema

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

Todo model

namespace App;
use Emadadly\LaravelUuid\Uuids;
use Illuminate\Database\Eloquent\Model;

class Todo extends Model
{
    use Uuids;

    protected $fillable = [
        'uuid', 'name', 'body',
    ];
}

todoController

namespace App\Http\Controllers;

use App\Todo;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class todoController extends Controller
{
    public function saveUUID(Request $request){

        $example = new Todo;

        $example->name = 'test';
        $example->body = 'body';
        $example->save();

    return response()->json(['example' => $example]);
    }
}

@emp-sean
Copy link
Author

Hi @EmadAdly
Thanks for responding, I did in fact get it working in the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants