forked from aslan/applicant-site
add User resource route, Controller
This commit is contained in:
parent
b7297c2fb7
commit
6dcf2c390f
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$users = User::all();
|
||||
return view('users.index', compact('users'));
|
||||
}
|
||||
|
||||
public function store($request)
|
||||
{
|
||||
if (Auth::guest()) {
|
||||
return redirect()->route('tasks.index');
|
||||
}
|
||||
|
||||
$validated = $request->validated();
|
||||
$createdById = Auth::id();
|
||||
$data = [...$validated, 'created_by_id' => $createdById];
|
||||
|
||||
$task = new User();
|
||||
$task->fill($data);
|
||||
$task->save();
|
||||
|
||||
if (array_key_exists('labels', $validated)) {
|
||||
$task->labels()->attach($validated['labels']);
|
||||
}
|
||||
|
||||
$message = __('controllers.tasks_create');
|
||||
return redirect()->route('tasks.index');
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
namespace Database\Seeders;
|
||||
|
||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<h2>список пользователей</h2>
|
||||
|
||||
<a href="{{ route('users.create') }}"> создать пользователя</a>
|
||||
<br>
|
||||
<br>
|
||||
<table class="mt-4">
|
||||
<thead class="border-b-2 border-solid border-black text-left" style="text-align: left">
|
||||
<tr>
|
||||
<th>id</th>
|
||||
<td>name</td>
|
||||
<td>email</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($users as $user)
|
||||
<tr>
|
||||
<td>{{ $user->id }}</td>
|
||||
<td>{{ $user->name }}</td>
|
||||
<td>{{ $user->email }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
{{--<table class="mt-4">--}}
|
||||
{{-- <thead class="border-b-2 border-solid border-black text-left" style="text-align: left">--}}
|
||||
{{-- <tr>--}}
|
||||
{{-- <th>{{ __('layout.table_id') }}</th>--}}
|
||||
{{-- <th>{{ __('layout.table_task_status') }}</th>--}}
|
||||
{{-- <th>{{ __('layout.table_name') }}</th>--}}
|
||||
{{-- <th>{{ __('layout.table_creater') }}</th>--}}
|
||||
{{-- <th>{{ __('layout.table_assigned') }}</th>--}}
|
||||
{{-- <th>{{ __('layout.table_date_of_creation') }}</th>--}}
|
||||
{{-- @auth()--}}
|
||||
{{-- <th>{{ __('layout.table_actions') }}</th>--}}
|
||||
{{-- @endauth--}}
|
||||
{{-- </tr>--}}
|
||||
{{-- </thead>--}}
|
||||
{{-- <tbody>--}}
|
||||
{{-- @foreach($tasks as $task)--}}
|
||||
{{-- <tr class="border-b border-dashed text-left">--}}
|
||||
{{-- <td>{{ $task->id }}</td>--}}
|
||||
{{-- <td>{{ $taskStatuses[$task->status_id] }}</td>--}}
|
||||
{{-- <td><a href="{{ route('tasks.show', $task) }}">{{ $task->name }}</a></td>--}}
|
||||
{{-- <td>{{ $users[$task->created_by_id] }}</td>--}}
|
||||
{{-- <td>{{ $users[$task->assigned_to_id] }}</td>--}}
|
||||
{{-- <td>{{ date_format($task->created_at, 'd.m.Y') }}</td>--}}
|
||||
{{-- @auth()--}}
|
||||
{{-- <td>--}}
|
||||
{{-- @can('delete', $task)--}}
|
||||
{{-- <a--}}
|
||||
{{-- class="text-red-600 hover:text-red-900"--}}
|
||||
{{-- rel="nofollow"--}}
|
||||
{{-- data-method="delete"--}}
|
||||
{{-- data-confirm="{{ __('layout.table_delete_question') }}"--}}
|
||||
{{-- href="{{ route('tasks.destroy', $task) }}"--}}
|
||||
{{-- >--}}
|
||||
{{-- {{ __('layout.table_delete') }}--}}
|
||||
{{-- </a>--}}
|
||||
{{-- @endcan--}}
|
||||
{{-- @can('update', $task)--}}
|
||||
{{-- <a class="text-blue-600 hover:text-blue-900"--}}
|
||||
{{-- href="{{ route("tasks.edit", $task) }}"--}}
|
||||
{{-- >--}}
|
||||
{{-- {{ __('layout.table_edit') }}--}}
|
||||
{{-- </a>--}}
|
||||
{{-- @endcan--}}
|
||||
{{-- </td>--}}
|
||||
{{-- @endauth--}}
|
||||
{{-- </tr>--}}
|
||||
{{-- @endforeach--}}
|
||||
{{-- </tbody>--}}
|
||||
{{--</table>--}}
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\ProfileController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
/*
|
||||
|
@ -16,7 +17,13 @@ use Illuminate\Support\Facades\Route;
|
|||
|
||||
Route::get('/', function () {
|
||||
return view('welcome');
|
||||
});
|
||||
})->name('home');
|
||||
|
||||
Route::resource('/users', UserController::class);
|
||||
|
||||
Route::get('/dashboard', function () {
|
||||
return view('dashboard');
|
||||
})->middleware(['auth', 'verified'])->name('dashboard');
|
||||
|
||||
Route::get('/dashboard', function () {
|
||||
return view('dashboard');
|
||||
|
|
Loading…
Reference in New Issue