TP6 et avant

This commit is contained in:
2026-10-07 16:34:12 +02:00
parent bb4ee689a1
commit e00d488df7
89 changed files with 11733 additions and 0 deletions
@@ -0,0 +1,14 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AboutController extends Controller
{
//
public function index()
{
return 'À propos de Mini-CRM';
}
}
@@ -0,0 +1,89 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Client;
use App\Http\Requests\StoreClientRequest;
use App\Http\Requests\UpdateClientRequest;
class ClientController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$search = $request->input('search');
$query = Client::query();
if ($search) {
$query->where(function ($query) use ($search) {
$query->where('name', 'like', '%' . $search . '%')
->orWhere('email', 'like', '%' . $search . '%')
->orWhere('city', 'like', '%' . $search . '%');
});
}
$clients = $query
->paginate(10)
->withQueryString();
return view('clients.index', compact('clients', 'search'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('clients.create');
}
/**
* Show the form for creating a new resource.
*/
public function store(StoreClientRequest $request)
{
Client::create($request->validated());
return redirect()->route('clients.index');
}
/**
* Display the specified resource.
*/
public function show(Client $client)
{
return view('clients.show', [
'client' => $client
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Client $client)
{
//
return view('clients.edit', [
'client' => $client
]);
}
/**
* Update the specified resource in storage.
*/
public function update(UpdateClientRequest $request, Client $client)
{
//
$client->update($request->validated());
return redirect()->route('clients.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Client $client)
{
//
$client->delete();
return redirect()->route('clients.index');
}
}
@@ -0,0 +1,17 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Client;
class ClientsController extends Controller
{ public function index()
{
$clients = Client::find(2);
return view('clients.index', [
'clients' => $clients
]);
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ContactController extends Controller
{
public function index()
{
$email = 'contact@mini-crm.test';
$phone = '01 23 45 67 89';
return view('contact', [
'email' => $email,
'phone' => $phone,
] );
}
}
@@ -0,0 +1,8 @@
<?php
namespace App\Http\Controllers;
abstract class Controller
{
//
}
@@ -0,0 +1,42 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public function index()
{
$company = 'ACME';
// $clients = 134;
$products = 48;
$orders = 83;
$name = 'Jean';
$city = 'Paris';
$stock = 3;
$clients = [
'Jean Dupont',
'Marie Martin',
'Paul Durand',
'Sophie Bernard'
];
$products = [
'Ordinateur',
'Écran',
'Clavier',
'Souris',
'Webcam'
];
return view('home', [
'company' => $company,
'clients' => $clients,
'products' => $products,
'orders' => $orders,
'name' => $name,
'city' => $city,
'stock' => $stock,
] );
}
}
@@ -0,0 +1,88 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Product;
use App\Http\Requests\StoreProductRequest;
use App\Http\Requests\UpdateProductRequest;
class ProductController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$search = $request->input('search');
$query = Product::query();
if ($search) {
$query->where(function ($query) use ($search) {
$query->where('name', 'like', '%' . $search . '%')
->orWhere('price', 'like', '%' . $search . '%')
->orWhere('stock', 'like', '%' . $search . '%');
});
}
$products = $query
->paginate(10)
->withQueryString();
return view('products.index', compact('products', 'search')); }
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('products.create');
}
/**
* Show the form for creating a new resource.
*/
public function store(StoreProductRequest $request)
{
Product::create($request->validated());
return redirect()->route('products.index');
}
/**
* Display the specified resource.
*/
public function show(Product $product)
{
return view('products.show', [
'product' => $product
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Product $product)
{
//
return view('products.edit', [
'product' => $product
]);
}
/**
* Update the specified resource in storage.
*/
public function update(UpdateProductRequest $request, Product $product)
{
//
$product->update($request->validated());
return redirect()->route('products.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Product $product)
{
//
$product->delete();
return redirect()->route('products.index');
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Product;
class ProductsController extends Controller
{
public function index()
{
$products = Product::all();
return view('products.index', [
'products' => $products
]);
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class StoreClientRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
'name' => 'required|string|max:100',
'email' => 'required|email',
'city' => 'nullable|string|max:100',
];
}
}
@@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class StoreProductRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
'name' => 'required|string|max:150',
'price' => 'required|integer|min:0',
'stock' => 'required|integer|min:0',
];
}
}
@@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class UpdateClientRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
'name' => 'required|string|max:100',
'email' => 'required|email',
'city' => 'nullable|string|max:100',
];
}
}
@@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class UpdateProductRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
'name' => 'required|string|max:150',
'price' => 'required|integer|min:0',
'stock' => 'required|integer|min:0',
];
}
}
+14
View File
@@ -0,0 +1,14 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Client extends Model
{
protected $fillable = [
'name',
'email',
'city',
];
}
+14
View File
@@ -0,0 +1,14 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = [
'name',
'price',
'stock',
];
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
#[Fillable(['name', 'email', 'password'])]
#[Hidden(['password', 'remember_token'])]
class User extends Authenticatable
{
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
}
}