1
0

remove chrips

This commit is contained in:
Rokas Puzonas 2023-10-29 22:47:41 +02:00
parent e5ef214753
commit 175018e906
13 changed files with 94 additions and 297 deletions

View File

@ -1,90 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Models\Chirp;
use Illuminate\Http\Request;
use Illuminate\View\View;
class ChirpController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(): View
{
return view("chirps.index", [
"chirps" => Chirp::with("user")->latest()->get()
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$validated = $request->validate([
"message" => "required|string|max:255"
]);
$request->user()->chirps()->create($validated);
return redirect(route("chirps.index"));
}
/**
* Display the specified resource.
*/
public function show(Chirp $chirp)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Chirp $chirp)
{
$this->authorize("update", $chirp);
return view("chirps.edit", [
"chirp" => $chirp
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Chirp $chirp)
{
$this->authorize("update", $chirp);
$validated = $request->validate([
"message" => "required|string|max:255"
]);
$chirp->update($validated);
return redirect(route("chirps.index"));
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Chirp $chirp)
{
$this->authorize("delete", $chirp);
$chirp->delete();
return redirect(route("chirps.index"));
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace App\Http\Controllers;
use App\Models\Test;
use Illuminate\Http\Request;
class TestTakingController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
return view("test-taking");
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(Test $test)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Test $test)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Test $test)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Test $test)
{
//
}
}

View File

@ -1,21 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Chirp extends Model
{
use HasFactory;
protected $fillable = [
"message"
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

View File

@ -45,11 +45,6 @@ class User extends Authenticatable
'password' => 'hashed',
];
public function chirps(): HasMany
{
return $this->hasMany(Chirp::class);
}
public function tests(): HasMany
{
return $this->hasMany(Test::class);

View File

@ -1,66 +0,0 @@
<?php
namespace App\Policies;
use App\Models\Chirp;
use App\Models\User;
use Illuminate\Auth\Access\Response;
class ChirpPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return true;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, Chirp $chirp): bool
{
return true;
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return true;
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Chirp $chirp): bool
{
return $chirp->user()->is($user);
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Chirp $chirp): bool
{
return $this->update($user, $chirp);
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Chirp $chirp): bool
{
return false;
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Chirp $chirp): bool
{
return false;
}
}

View File

@ -1,29 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chirps', function (Blueprint $table) {
$table->id();
$table->foreignId("user_id")->constrained()->cascadeOnDelete();
$table->string("message");
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chirps');
}
};

View File

@ -15,5 +15,7 @@
"Save": "Saugoti",
"Cancel": "Atšaukti",
"Create test": "Sukurti testą",
"Tests": "Testai"
"Tests": "Testai",
"Take tests": "Laikyti testą",
"Dashboard": "Pagrindinis"
}

View File

@ -1,14 +0,0 @@
<x-app-layout>
<div class="max-w-2xl mx-auto p-4 sm:p-6 lg:p-8">
<form method="POST" action="{{ route('chirps.update', $chirp) }}">
@csrf
@method("patch")
<textarea name="message" class="block w-full border-gray-300 focus:order-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm">{{ old("message", $chirp->message) }}</textarea>
<x-input-error :messages="$errors->get('message')" class="mt-2" />
<div class="mt-4 space-x-2">
<x-primary-button>{{ __("Save") }}</x-primary-button>
<a href="{{ route('chirps.index') }}">{{ __("Cancel") }}</a>
</div>
</form>
</div>
</x-app-layout>

View File

@ -1,56 +0,0 @@
<x-app-layout>
<div class="max-w-2xl mx-auto p-4 sm:p-6 lg:p-8">
<form method="POST" action="{{ route('chirps.store') }}">
@csrf
<textarea name="message" placeholder="{{ __('What\'s on your mind?') }}" class="block w-full border-gray-300 focus:border-indigo-300 focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm">{{ old('message') }}</textarea>
<x-input-error :messages="$errors->get('message')" class="mt-2" />
<x-primary-button class="mt-4">{{ __('Chirp') }}</x-primary-button>
</form>
<div class="mt-6 bg-white shadown-sm rounded-lg divide-y">
@foreach ($chirps as $chirp)
<div class="p-6 flex space-x-2">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-gray-600 -scale-x-100" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
</svg>
<div class="flex-1">
<div class="flex justify-between items-center">
<div>
<span class="text-gray-800">{{ $chirp->user->name }}</span>
<small class="ml-2 text-sm text-gray-600">{{ $chirp->created_at->format("j M Y, g:i a") }}</small>
@unless ($chirp->created_at->eq($chirp->updated_at))
<small class="text-sm text-gray-600"> &middot; {{ __("edited") }}</small>
@endunless
</div>
@if ($chirp->user->is(auth()->user()))
<x-dropdown>
<x-slot name="trigger">
<button>
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-gray-400" viewBox="0 0 20 20" fill="currentColor">
<path d="M6 10a2 2 0 11-4 0 2 2 0 014 0zM12 10a2 2 0 11-4 0 2 2 0 014 0zM16 12a2 2 0 100-4 2 2 0 000 4z" />
</svg>
</button>
</x-slot>
<x-slot name="content">
<x-dropdown-link :href="route('chirps.edit', $chirp)">
{{ __("Edit") }}
</x-dropdown-link>
<form method="POST" action="{{ route("chirps.destroy", $chirp) }}">
@csrf
@method("delete")
<x-dropdown-link :href="route('chirps.destroy', $chirp)" onclick="event.preventDefault(); this.closest('form').submit();">
{{ __("Delete") }}
</x-dropdown-link>
</form>
</x-slot>
</x-dropdown>
@endif
</div>
<p class="mt-4 text-lg text-gray-900">{{ $chirp->message }}</p>
</div>
</div>
@endforeach
</div>
</div>
</x-app-layout>

View File

@ -8,10 +8,10 @@
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900">
{{ __("You're logged in!") }}
{{ Auth::user()->role }}
</div>
{{-- <div class="p-6 text-gray-900"> --}}
{{-- {{ __("You're logged in!") }} --}}
{{-- {{ Auth::user()->role }} --}}
{{-- </div> --}}
</div>
</div>
</div>

View File

@ -15,9 +15,6 @@
<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
{{ __('Dashboard') }}
</x-nav-link>
<x-nav-link :href="route('chirps.index')" :active="request()->routeIs('chirps.index')">
{{ __('Chirps') }}
</x-nav-link>
@if (Auth::user()->role == "admin")
<x-nav-link :href="route('users.index')" :active="request()->routeIs('users.index')">
{{ __('Users') }}
@ -28,6 +25,11 @@
{{ __('Tests') }}
</x-nav-link>
@endif
@if (Auth::user()->role == "student")
<x-nav-link :href="route('take-tests')" :active="request()->routeIs('take-tests')">
{{ __('Take tests') }}
</x-nav-link>
@endif
</div>
</div>
@ -83,9 +85,6 @@
<x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
{{ __('Dashboard') }}
</x-responsive-nav-link>
<x-responsive-nav-link :href="route('chirps.index')" :active="request()->routeIs('chirps.index')">
{{ __('Chirps') }}
</x-responsive-nav-link>
@if (Auth::user()->role == "admin")
<x-responsive-nav-link :href="route('users.index')" :active="request()->routeIs('users.index')">
{{ __('Users') }}
@ -96,6 +95,11 @@
{{ __('Tests') }}
</x-responsive-nav-link>
@endif
@if (Auth::user()->role == "student")
<x-responsive-nav-link :href="route('take-tests')" :active="request()->routeIs('take-tests')">
{{ __('Take tests') }}
</x-responsive-nav-link>
@endif
</div>
<!-- Responsive Settings Options -->

View File

@ -0,0 +1,4 @@
<x-app-layout>
<div class="max-w-2xl mx-auto p-4 sm:p-6 lg:p-8">
</div>
</x-app-layout>

View File

@ -1,6 +1,5 @@
<?php
use App\Http\Controllers\ChirpController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\QuestionController;
use App\Http\Controllers\TestController;
@ -32,10 +31,6 @@ Route::middleware('auth')->group(function () {
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});
Route::resource("chirps", ChirpController::class)
->only(["index", "store", "edit", "update", "destroy"])
->middleware(["auth", "verified"]);
Route::resource("users", UserController::class)
->only(["index", "store", "edit", "update", "destroy"])
->middleware(["auth", "verified"]);
@ -48,4 +43,12 @@ Route::resource("questions", QuestionController::class)
->only(["index", "store", "edit", "update", "destroy"])
->middleware(["auth", "verified"]);
Route::get('/take-tests', function () {
return view('take-tests');
})->middleware(['auth', 'verified'])->name('take-tests');
// Route::resource("test-taking", TestTakingController::class)
// ->only(["index"])
// ->middleware(["auth", "verified"]);
require __DIR__.'/auth.php';