Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test9 #228

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

test9 #228

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
4 changes: 2 additions & 2 deletions app/Http/Controllers/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public function store(Request $request)
public function show(Company $company)
{
// TASK: retrieve the full URL to the uploaded photo file, using Spatie Media Library
$photo = '???';

$photo = $company->getMedia('companies')[0]->getFullUrl();

return view('companies.show', compact('company', 'photo'));
}

}
14 changes: 14 additions & 0 deletions app/Http/Controllers/HouseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function update(Request $request, House $house)

// TASK: Delete the old file from the storage

// حذف الملف القديم من التخزين

Storage::delete($house->photo);

$house->update([
'name' => $request->name,
'photo' => $filename,
Expand All @@ -38,5 +42,15 @@ public function download(House $house)
{
// TASK: Return the $house->photo file from "storage/app/houses" folder
// for download in browser
$filePath = 'houses/' . $house->photo;

// التحقق إذا كان الملف موجودًا
if (Storage::exists($filePath)) {
// إرجاع الملف ليتم تحميله عبر المتصفح
return Storage::download($filePath);
}

// إذا لم يكن الملف موجودًا، إرجاع خطأ 404
return abort(404, 'File not found');
}
}
14 changes: 10 additions & 4 deletions app/Http/Controllers/OfficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ class OfficeController extends Controller
{
public function store(Request $request)
{
// التحقق من وجود الملف في الطلب
$request->validate([
'photo' => 'required|file|max:1024', // التحقق من أن الملف موجود ولا يتجاوز 1 ميجابايت
]);

// الحصول على اسم الملف الأصلي
$filename = $request->file('photo')->getClientOriginalName();

// TASK: Upload the file "photo" so it would be written as
// storage/app/public/offices/[original_filename]
// رفع الملف إلى المجلد 'public/offices' وتخزينه مع الاسم الأصلي
$path = $request->file('photo')->storeAs('public/offices', $filename);

// إنشاء السجل الجديد في قاعدة البيانات
Office::create([
'name' => $request->name,
'photo' => $filename,
'photo' => $filename, // حفظ اسم الملف في قاعدة البيانات
]);

return 'Success';
Expand All @@ -26,5 +33,4 @@ public function show(Office $office)
{
return view('offices.show', compact('office'));
}

}
4 changes: 3 additions & 1 deletion app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@

use App\Models\Project;
use Illuminate\Http\Request;
use Illuminate\Validation\Rules\File;

class ProjectController extends Controller
{
public function store(Request $request)
{
$request->validate([
// TASK: Write the validation rule so "logo" file would be MAX 1 megabyte
'logo' => [File::image()->max(1024)]
]);

// TASK: change the below line so that $filename would contain only filename
// The same filename as the original uploaded file
$filename = '???';
$filename = $request->logo->getClientOriginalName();
$request->file('logo')->storeAs('logos', $filename);

Project::create([
Expand Down
15 changes: 12 additions & 3 deletions app/Http/Controllers/ShopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ class ShopController extends Controller
{
public function store(Request $request)
{
// 1. الحصول على اسم الملف الأصلي
$filename = $request->file('photo')->getClientOriginalName();

// 2. رفع الصورة إلى المجلد 'shops'
$request->file('photo')->storeAs('shops', $filename);

// TASK: resize the uploaded image from /storage/app/shops/$filename
// to size of 500x500 and store it as /storage/app/shops/resized-$filename
// Use intervention/image package, it's already pre-installed for you
// 3. تغيير حجم الصورة باستخدام Intervention Image
$image = Image::make(storage_path('app/shops/' . $filename)); // تحميل الصورة من المسار

// 4. تغيير الحجم إلى 500x500 بيكسل
$image->resize(500, 500);

// 5. حفظ الصورة المعدلة باسم جديد (resized-{$filename})
$resizedFilename = 'resized-' . $filename;
$image->save(storage_path('app/shops/' . $resizedFilename)); // حفظ الصورة المعدلة في المجلد نفسه

return 'Success';
}
Expand Down
Loading