finished validation of habit; added tag inits
This commit is contained in:
parent
5d9f85b0c0
commit
8acb38a523
@ -23,7 +23,10 @@ public function create()
|
|||||||
|
|
||||||
public function store(HabitsRequest $request)
|
public function store(HabitsRequest $request)
|
||||||
{
|
{
|
||||||
dd($request);
|
$validata = $request->safe()->merge(['user_id' => Auth::id()]);
|
||||||
|
Habit::create($validata->all());
|
||||||
|
|
||||||
|
return redirect()->route('habits.index')->with('status', 'created');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
|
@ -10,7 +10,14 @@ public function rules(): array
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => ['required', 'string'],
|
'name' => ['required', 'string'],
|
||||||
''
|
'type' => ['required', 'string'],
|
||||||
|
'value' => ['numeric'],
|
||||||
|
'suffix' => ['string'],
|
||||||
|
'schedule_value' => ['numeric'],
|
||||||
|
'schedule_unit' => [],
|
||||||
|
'goal_type' => ['required'],
|
||||||
|
'goal_value' => ['numeric'],
|
||||||
|
'goal_unit' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
app/Http/Requests/TagRequest.php
Normal file
15
app/Http/Requests/TagRequest.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class TagRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => ['required'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
16
app/Models/Tag.php
Normal file
16
app/Models/Tag.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class Tag extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes, HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
];
|
||||||
|
}
|
18
database/factories/TagFactory.php
Normal file
18
database/factories/TagFactory.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Tag;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
class TagFactory extends Factory
|
||||||
|
{
|
||||||
|
protected $model = Tag::class;
|
||||||
|
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => $this->faker->name(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
22
database/migrations/2023_05_26_143121_create_tags_table.php
Normal file
22
database/migrations/2023_05_26_143121_create_tags_table.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration {
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('tags', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->softDeletes();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('tags');
|
||||||
|
}
|
||||||
|
};
|
@ -27,12 +27,15 @@
|
|||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
<x-input-label for="habit_type" value="Habit Type"></x-input-label>
|
<x-input-label for="habit_type" value="Habit Type"></x-input-label>
|
||||||
<div class="flex items-center mb-1">
|
<div class="flex items-center mb-1">
|
||||||
<!-- Radio button 1 -->
|
|
||||||
|
<!-- Radio button: todo-->
|
||||||
<input id="habit-type-1" type="radio" value="todo" name="type"
|
<input id="habit-type-1" type="radio" value="todo" name="type"
|
||||||
onclick="toggleHabitValueSuffix(true)"
|
onclick="toggleHabitValueSuffix(true)" checked
|
||||||
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
||||||
<label for="habit-type-1" class="ml-2">Todo / done</label>
|
<label for="habit-type-1" class="ml-2">Todo / done</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Radio button: value-->
|
||||||
<div class="flex items-center mb-1">
|
<div class="flex items-center mb-1">
|
||||||
<input id="habit-type-2" type="radio" value="value" name="type"
|
<input id="habit-type-2" type="radio" value="value" name="type"
|
||||||
onclick="toggleHabitValueSuffix(false)"
|
onclick="toggleHabitValueSuffix(false)"
|
||||||
@ -46,13 +49,13 @@ class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark
|
|||||||
|
|
||||||
<x-text-input id="habit-value-amount" class="inline-block mt-1" type="number"
|
<x-text-input id="habit-value-amount" class="inline-block mt-1" type="number"
|
||||||
placeholder="Numeric value" min="0"
|
placeholder="Numeric value" min="0"
|
||||||
name="value" disabled/>
|
name="value" required disabled/>
|
||||||
<x-input-error :messages="$errors->get('value')" class="mt-2"/>
|
<x-input-error :messages="$errors->get('value')" class="mt-2"/>
|
||||||
|
|
||||||
<x-text-input id="habit-suffix-name" class="inline-block mt-1 disabled:opacity-50"
|
<x-text-input id="habit-suffix-name" class="inline-block mt-1 disabled:opacity-50"
|
||||||
type="text" name="suffix" disabled
|
type="text" name="suffix" disabled required
|
||||||
placeholder="Suffix"
|
placeholder="Suffix"
|
||||||
:value="old('suffix')" required autofocus autocomplete="suffix"/>
|
:value="old('suffix')" autofocus autocomplete="suffix"/>
|
||||||
<x-input-error :messages="$errors->get('suffix')" class="mt-2"/>
|
<x-input-error :messages="$errors->get('suffix')" class="mt-2"/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -88,7 +91,7 @@ class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex items-center mb-1">
|
<div class="flex items-center mb-1">
|
||||||
<input id="goal-type-2" type="radio" value="schedule" name="goal_type"
|
<input id="goal-type-2" type="radio" value="schedule" name="goal_type"
|
||||||
checked="checked" onclick="toggleGoalSchedule(true)"
|
checked onclick="toggleGoalSchedule(true)"
|
||||||
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
||||||
<label for="goal-type-2" class="ml-2 ">Same as schedule</label>
|
<label for="goal-type-2" class="ml-2 ">Same as schedule</label>
|
||||||
</div>
|
</div>
|
||||||
@ -100,16 +103,16 @@ class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- goal-schedule -->
|
<!-- goal schedule -->
|
||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
<x-input-label for="goal-schedule-unit" value="Goal Schedule"></x-input-label>
|
<x-input-label for="goal-schedule-unit" value="Goal Schedule"></x-input-label>
|
||||||
|
|
||||||
<x-text-input id="goal-schedule-amount" class="inline-block mt-1" type="number"
|
<x-text-input id="goal-schedule-amount" class="inline-block mt-1" type="number"
|
||||||
placeholder="Numeric value" min="0" disabled
|
placeholder="Numeric value" min="0" disabled required
|
||||||
name="goal_value"/>
|
name="goal_value"/>
|
||||||
|
|
||||||
<select name="goal_unit" id="goal-schedule-unit"
|
<select name="goal_unit" id="goal-schedule-unit"
|
||||||
disabled
|
disabled required
|
||||||
class="inline-block w-1/2 border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm disabled:opacity-50">
|
class="inline-block w-1/2 border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm disabled:opacity-50">
|
||||||
<option value="day">Days</option>
|
<option value="day">Days</option>
|
||||||
<option value="week">Weeks</option>
|
<option value="week">Weeks</option>
|
||||||
|
@ -27,9 +27,6 @@
|
|||||||
<th scope="col" class="px-6 py-2">
|
<th scope="col" class="px-6 py-2">
|
||||||
{{-- Edit--}}
|
{{-- Edit--}}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-2">
|
|
||||||
{{-- Delete--}}
|
|
||||||
</th>
|
|
||||||
<th>
|
<th>
|
||||||
|
|
||||||
</th>
|
</th>
|
||||||
@ -53,12 +50,6 @@
|
|||||||
<x-primary-button>Edit</x-primary-button>
|
<x-primary-button>Edit</x-primary-button>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-4 py-2">
|
|
||||||
<form action="{{route('habits.destroy', $habit)}}" method="get">
|
|
||||||
@csrf
|
|
||||||
<x-danger-button>Delete</x-danger-button>
|
|
||||||
</form>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user