Kenoli
Kenoli

Reputation: 39

Unable to run artisan using eloquent and unable to create a new record in my table

I'm using eloquent without laravel installed. I'm having trouble finding simple tutorials for eloquent that I can understand or that give me instructions that actually work. My installation of Eloquent works for selecting records, enterring data in a field and more, but I am having some problems. I am trying to add a new record to my database. The one I found wants me to use "DB::' but it seems that I need to use artisan from the terminal to set that up.

When I run artisan from the terminal I get 'Could not open input file: artisan'.

I have read the admonition that this means I need to be in the root folder and that will solve my problem. I am there. I'm able to use eloquent from that folder. It is where I installed composer and eloquent. I also read that the Artisan.php file may not have the right permissions. I tried using chmod on it and was refused. I should think that when composer installed eloquent it would have given it the right permissions but I tried anyway.

When I tried another route I got a mass assignment error and am aware of security issues related to mass assignment, but when creating a new record, I do need to fill in the fields of the new record. I don't understand enough to know what the mass assignment error is telling me to do.

Here's what I tried:

Artists::insert(array(
    'fname' => 'Harry',
    'lname' => 'Potter',
    'tio' => 'yes',
    'preview' => 'yes',
    'telephone' => '510-717-1776'
));

Here's the error:

Fatal error: Uncaught Illuminate\Database\Eloquent\MassAssignmentException: Add [fname] to fillable property to allow mass assignment on [Artists]. in /Users/studio-kenoli/Sites/BannerProject/as/vendor/illuminate/database/Eloquent/Model.php:354 Stack trace: #0 /Users/studio-kenoli/Sites/BannerProject/as/vendor/illuminate/database/Eloquent/Model.php(174): Illuminate\Database\Eloquent\Model->fill(Array) #1 /Users/studio-kenoli/Sites/BannerProject/as/vendor/illuminate/database/Eloquent/Model.php(404): Illuminate\Database\Eloquent\Model->__construct(Array) #2 /Users/studio-kenoli/Sites/BannerProject/as/vendor/illuminate/database/Eloquent/Builder.php(1208): Illuminate\Database\Eloquent\Model->newInstance(Array) #3 /Users/studio-kenoli/Sites/BannerProject/as/vendor/illuminate/database/Eloquent/Builder.php(776): Illuminate\Database\Eloquent\Builder->newModelInstance(Array) #4 /Users/studio-kenoli/Sites/BannerProject/as/vendor/illuminate/support/Traits/ForwardsCalls.php(23): Illuminate\Database\Eloquent\Builder->create(Array) #5 in /Users/studio-kenoli/Sites/BannerProject/as/vendor/illuminate/database/Eloquent/Model.php on line 354

The name of the table is artists and I did create a model for the table. It works in other contexts. I guessed at "insert". I also tried "create" which fell flat on its face. I'm finding eloquent quite difficult to use and quite difficult to get simple information about how to to the simple CRUD operations that I need to use it for.

Upvotes: 1

Views: 147

Answers (1)

Kenoli
Kenoli

Reputation: 39

I was unable to find out how to use artisan, but I was able to find a work around using direct eloquent commands.

Thanks for the help offered.

--Kenoli

Upvotes: 1

Related Questions