Now that we have Employees - they usually have to perform specific Tasks with our Customers. For example, they might need to make a phone call to them or send over some documents. For that, we can build a Task system with a calendar view like this:

In this lesson, we will do the following:
- Create Task Model and Database
- Add the Create Task button to the Customer list
- Add Task list to the Customer page (view page)
- Add Task Resource with Tabs
- Add a Calendar page for Tasks
Create Task Model and Database
Let's start with our Models and Database structure:
Migration
use App\Models\Customer;use App\Models\User; // ... Schema::create('tasks', function (Blueprint $table) { $table->id(); $table->foreignIdFor(Customer::class)->constrained(); $table->foreignIdFor(User::class)->nullable()->constrained(); $table->text('description'); $table->date('due_date')->nullable(); $table->boolean('is_completed')->default(false); $table->timestamps();});
Then, we can fill our Model:
app/Models/Task.php
use Illuminate\Database\Eloquent\Relations\BelongsTo; class Task extends Model{ protected $fillable = [ 'customer_id', 'user_id', 'description', 'due_date', 'is_completed', ]; protected $casts = [ 'due_date' => 'date', 'is_completed' => 'boolean', ]; public function customer(): BelongsTo { return $this->belongsTo(Customer::class); } public function employee(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); }}
That's it. We have our base structure for the Task Model and Database.
Add Create Task Button to the Customer list
Next, we want to add a button to...
Question how do we go about changing the time for the task the only thing coming up is 12a in front of every task?
If you need the time - you need to have
dateTimecolumn on your tasks and not justdate. That is indeed a limitation on the calendar integration - it sets 12am as default date if none is provided.If you add this: ->allDay(true)
to the EventData::make() you will render them without time, so it won't display 12a or 00 in front of the events.
Helo, thanks for wonderful course. I hit a problem I am not able to solve. In CustomerResource Infolist on Tabs with Tasks there is ->suffixAction at is_completed TextEntry. If I use the action with the closure: ->action(function (Task $record) { $record->is_completed = true; $record->save(); i got an axception, that the model Customer instead of model Task was provided to the closure. It seems it injects the $record of the main record of the infolist = Customer and not the actual record of the repeatable entry.
Hi guys,
I just found out that something strange happens with table action form.
When we select employee in the form, somehow it automatically updates the $customer employee_id to selected user_id...
->action(function (Customer $customer, array $data) { dd($customer, Customer::find($customer->id)); })
It is happening when we use ->relationship('employee', 'name'), to fix it we can change it to ->options(User::all()->pluck('name', 'id')) but it is strange it is doing that in the background.
Hi, I'm not sure I fully understood the issue you are facing here.
Does this happen on an action when you have more than one row selected? What about just a single row selected, is it working as expected?
It happens on this form:
Tables\Actions\Action::make('Add Task') ->icon('heroicon-s-clipboard-document') ->form([ Forms\Components\RichEditor::make('description') ->required(), Forms\Components\Select::make('user_id') ->preload() ->searchable() ->relationship('employee', 'name'), Forms\Components\DatePicker::make('due_date') ->native(false),
Its per record
Hmm, I have not experienced this. Could you dump the
$datausingdd($data)and see what it returns? As it shouldn't set the employee id, unless you have an employee ID on the form...Or maybe something happens if you have more than 1 record selected and try to create a task - not sure
Its not problem in the data. Forms\Components\Select::make('user_id') ->preload() ->searchable() ->relationship('employee', 'name')
This like auto-populates employee_id when it is using relationship, if you dd($customer) you can see it changes it when the select changes..
This is weird. I don't see such behaviour, and I don't remember it being like this...
I new and learing. If I use UTC time on the app and have a timezone field for my user, how can I have the text column adjust from UTC to customer's time zone? This is probably easy to do but i've searched and couldn't find anything specific to filament. Right now I have a text column that shows the timestamp from my database, I really need to recalucate the proper time before displaying. Any help will be greatly appreciated. Thank you.
Hi, then this course would help you:
https://laraveldaily.com/course/laravel-user-timezones?mtm_campaign=search-results-course
Thank you very much. Please when i add this to CustomerResource below i'm encountering an error.
Tables\Actions\Action::make('Add Task') ->icon('heroicon-s-clipboard-document') ->form([ Forms\Components\RichEditor::make('description') ->required(), Forms\Components\Select::make('user_id') ->preload() ->searchable() ->relationship('employee', 'name'), Forms\Components\DatePicker::make('due_date') ->native(false),
What is the error?
I've fixed that. thank you.
O lecture fifteen. Im havig difficultyu in creating a Calendar widget. It shows
Unable to find component: [App\Livewire\TaskCalendarWidget]
after following your procedures. Thanks for quick response.
It seems that you don't have the widget class declared correctly. Please check the file that's below the
bladecode snippetResolved. Thank you so much.