Skip to content

Commit 98c0b93

Browse files
Merge pull request #4 from Valeria110/GS-3032
[update] update Gantt + Laravel tutorial
2 parents 7e711db + f871c48 commit 98c0b93

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

docs/integrations/php/howtostart-php-laravel.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ Create a new application using [Composer](https://getcomposer.org/):
3737
composer create-project laravel/laravel gantt-laravel-app
3838
~~~
3939

40-
It should take a minute to download and create all necessary files.
41-
Once everything is done, you can check that everything is correct so far:
40+
It should take a minute to download and create all necessary files.
41+
Once everything is done, you can check that everything is correct so far. Go the project folder and run database migrations:
4242

4343
~~~php
4444
cd gantt-laravel-app
45+
php artisan migrate
46+
~~~
47+
48+
Now, you can run the server:
49+
50+
~~~php
4551
php artisan serve
4652
~~~
4753

@@ -323,7 +329,7 @@ The Task model will look as in:
323329
~~~php title="/app/Models/Task.php"
324330
<?php
325331

326-
namespace App;
332+
namespace App\Models;
327333

328334
use Illuminate\Database\Eloquent\Model;
329335

@@ -343,7 +349,7 @@ And the Link model doesn't need any changes:
343349
~~~php title="/app/Models/Link.php"
344350
<?php
345351

346-
namespace App;
352+
namespace App\Models;
347353

348354
use Illuminate\Database\Eloquent\Model;
349355

@@ -509,6 +515,34 @@ class TaskController extends Controller
509515
}
510516
~~~
511517

518+
519+
#### Configuring the Task model
520+
521+
Before the controller methods will work, we need to configure the `Task` model to allow mass assignment. [Laravel's mass assignment](https://laravel.com/docs/11.x/eloquent#mass-assignment) protection requires you to explicitly specify which attributes can be filled using the `create()` and `update()` methods.
522+
Update your Task model to include the `$fillable` property:
523+
524+
~~~php title="app/Models/Task.php"
525+
<?php
526+
527+
namespace App\Models;
528+
529+
use Illuminate\Database\Eloquent\Model;
530+
531+
class Task extends Model
532+
{
533+
protected $fillable = ['text', 'start_date', 'duration', 'progress', 'parent']; /*!*/
534+
protected $appends = ["open"];
535+
536+
public function getOpenAttribute(){
537+
return true;
538+
}
539+
}
540+
~~~
541+
542+
The `$fillable` array specifies which fields can be mass-assigned. This is a security feature that protects against unwanted fields being updated through user input.
543+
544+
545+
512546
And a [route](https://laravel.com/docs/12.x/controllers#resource-controllers) for it:
513547

514548

@@ -577,6 +611,24 @@ class LinkController extends Controller
577611
}
578612
~~~
579613

614+
#### Configuring the Link model
615+
616+
Similarly to the Task model, we need to configure the Link model for mass assignment:
617+
618+
~~~php title="app/Models/Link.php"
619+
<?php
620+
621+
namespace App\Models;
622+
623+
use Illuminate\Database\Eloquent\Model;
624+
625+
class Link extends Model
626+
{
627+
protected $fillable = ['type', 'source', 'target']; /*!*/
628+
}
629+
~~~
630+
631+
580632
And its routes:
581633

582634

0 commit comments

Comments
 (0)