Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions app/Http/Controllers/EloquentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function task2()
// TODO Eloquent Задание 2: С помощью модели Item реализовать запрос в переменной products
// select * from products where active = true order by created_at desc limit 3
// вместо []
$products = [];
$products = Item::where('active',true)->orderBy('created_at','DESC')->take(3)->get();

return view('eloquent.task2', [
'products' => $products
Expand All @@ -36,24 +36,31 @@ public function task4($id)
// TODO Eloquent Задание 4: Найти Item по id и передать во view либо отдать 404 страницу
// Одна строка кода
// вместо []
$product = [];
$product = Item::whereid($id)->first();
if($product){
return view('eloquent.task4', [
'product' => $product
]);
}
else{
abort(404);
}

return view('eloquent.task4', [
'product' => $product
]);
}

public function task5(Request $request)
{
// TODO Eloquent Задание 5: В запросе будет все необходимое для создания записи
// Выполнить простое добавление новой записи в Item на основе $request
Item::create($request->except('crsf_token'));

return redirect('/');
}

public function task6($id, Request $request)
{
$product = Item::findOrFail($id);
$product->update($request->except('crsf_token'));
// TODO Eloquent Задание 6: В запросе будет все необходимое для обновления записи
// Выполнить простое обновление записи на основе $request

Expand All @@ -62,9 +69,10 @@ public function task6($id, Request $request)

public function task7(Request $request)
{

// TODO Eloquent Задание 7: В запросе будет параметр products который будет содержать массив с id
// [1,2,3,4 ...] выполнить массовое удаление записей модели Item с учетом id в $request

$product = Item::whereIn('id',$request->input("products"))->delete();
return redirect('/');
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function index()

return view('welcome', [
'title' => 'Welcome',
'users'=>$users,
// TODO Blade Задание 1: Передайте users во view (название ключа users)
]);
}
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/ItemStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function authorize()
public function rules()
{
return [
'title'=>'required|string|min:5|max:15',
//TODO Validation Задание: Добавить правила валидации для поля title
// Поле обязательно
// Строковое
Expand Down
15 changes: 13 additions & 2 deletions app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\article;

class Category extends Model
{
use HasFactory;

use HasFactory,SoftDeletes;
protected $fillable = ['title'];

/**
* The article t
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function article()
{
return $this->belongsToMany(article::class, 'article_category', 'article_id', 'category_id');
}
}
2 changes: 1 addition & 1 deletion app/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Item extends Model
{
use HasFactory;

protected $table='products';
protected $fillable = ['title', 'active'];

// TODO Eloquent Задание 1: указать что таблица - products
Expand Down
4 changes: 2 additions & 2 deletions app/Policies/ItemPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function view(User $user, Item $item)
public function create(User $user)
{
// TODO Auth Задание: Разрешить добавление продуктов только пользователю с id = 10

return true;
if($user->id==10) return true;
return false;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AppServiceProvider extends ServiceProvider
public function register()
{
//

}

/**
Expand All @@ -25,6 +26,6 @@ public function register()
*/
public function boot()
{

Blade::component('hello', HelloWorld::class);
}
}
28 changes: 28 additions & 0 deletions app/View/Components/HelloWorld.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\View\Components;

use Illuminate\View\Component;

class HelloWorld extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.hello-world');
}
}
5 changes: 5 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use App\View\Components\HelloWorld;

return [

/*
Expand Down Expand Up @@ -165,6 +167,7 @@
/*
* Package Service Providers...
*/
// App\View\Components\HelloWorld::class,

/*
* Application Service Providers...
Expand Down Expand Up @@ -230,6 +233,8 @@
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,

// 'Hello'=>App\View\Components\HelloWorld::class,

],

];
34 changes: 34 additions & 0 deletions database/migrations/2022_04_11_114946_create_categories_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('title')->nullable()->default(null);
$table->text('description')->nullable();
$table->softDeletes();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('categories');
}
}
36 changes: 36 additions & 0 deletions database/migrations/2022_04_11_120058_create_articles_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateArticlesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->id();
$table->string('name')->nullable()->default(null);
$table->string('description');
$table->boolean('active')->default(true);
$table->boolean('main')->default(false);
$table->softDeletes();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('articles');
}
}
34 changes: 34 additions & 0 deletions database/migrations/2022_04_12_033316_article_category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class ArticleCategory extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('article_category', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('category_id');
$table->unsignedBigInteger('article_id');
$table->softDeletes();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
5 changes: 4 additions & 1 deletion resources/views/auth.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!-- TODO Blade Задание 4: Сделать проверку авторизован пользователь или нет -->
@if(Auth::check())
{{Auth::id()}}
@endif
<!-- Если да то вывести ID пользователя -->
<!-- ID пользователя вывести внутри конструкции с проверкой -->
<!-- ID пользователя вывести внутри конструкции с проверкой -->
3 changes: 3 additions & 0 deletions resources/views/components/hello-world.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
{{now()->format('Y-m-d')}}
</div>
1 change: 1 addition & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<body class="antialiased">
<!-- TODO Blade Задание 3: Подключите view с меню -->
<!-- shared/menu.blade.php -->
@include('shared.menu')

@yield('content')
</body>
Expand Down
14 changes: 13 additions & 1 deletion resources/views/table.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- TODO Blade Задание 2: Изменить реализацию этой view, расширить ее с использованием layout -->
<!-- layouts/app.blade.php -->

@extends('layouts.app')

<!-- TODO Blade Задание 6: В эту view с контроллера передается collection c users в переменной data -->
<!-- Выполнить foreach loop в одну строку -->
Expand All @@ -11,4 +11,16 @@
<!-- TODO Blade Задание 7: Здесь сделайте классический foreach loop -->
<!-- Выведите div с $user->name -->
<!-- Воспользуйтесь переменной $loop и у нечетных div выведите класс - bg-red-500 -->
{{-- @dd($data) --}}
@if($data->count()>0)
@foreach ($data as $key=>$item)

<div class="@if((($key+1)%2)==0) bg-red-500 @endif">
{{$item->name}}
</div>

@endforeach
@else
<div>Ничего не найдено
</div>
@endif
3 changes: 3 additions & 0 deletions resources/views/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@
}
</style>
</head>
<h1>Welcome</h1>
<body class="antialiased">
<div class="relative flex items-top justify-center min-h-screen bg-gray-100 dark:bg-gray-900 sm:items-center py-4 sm:pt-0">

<!-- TODO Blade Задание 5: Сделать blade component с названием HelloWorld -->

<!-- с содержимым во view - Текущая дата в формате Y-m-d -->
<!-- Обязательно условие добавить регистрацию компонента в AppServiceProvider -->
<!-- и изменить его alias на hello -->
<!-- В итоге alias - hello а класс компонента App\View\Components\HelloWorld -->
<!-- и вывести его здесь -->
<x-hello></x-hello>
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\Api\V1\UserController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Expand All @@ -12,4 +13,7 @@
// Префикс урла должен быть /api/v1
// Полный урл /api/v1/users (не забывайте что это api routes)
// Одна строка кода
Route::prefix('v1')->group(function () {
route::apiResource('users',UserController::class);
});
});
Loading