|
|
@@ -207,13 +207,15 @@ class NewsController extends Controller
|
|
|
Log::info('=== NEWS STORE METHOD START ===');
|
|
|
Log::info('Request data:', $request->all());
|
|
|
Log::info('Request method:', [$request->method()]);
|
|
|
+ Log::info('Has files:', [$request->hasFile('image')]);
|
|
|
+ Log::info('Files data:', $request->file());
|
|
|
|
|
|
try {
|
|
|
$request->validate($this->rules);
|
|
|
Log::info('Validation passed');
|
|
|
|
|
|
$input = $request->all();
|
|
|
- Log::info('Input data:', $input);
|
|
|
+ Log::info('Input data after validation:', $input);
|
|
|
|
|
|
// Check which button was clicked
|
|
|
if (isset($input['save'])) {
|
|
|
@@ -228,62 +230,109 @@ class NewsController extends Controller
|
|
|
if (isset($input['unpublish'])) {
|
|
|
Log::info('UNPUBLISH button clicked');
|
|
|
}
|
|
|
+ if (isset($input['crop'])) {
|
|
|
+ Log::info('CROP button clicked');
|
|
|
+ }
|
|
|
|
|
|
- // Image handling
|
|
|
- if (request()->image) {
|
|
|
- Log::info('Processing main image upload');
|
|
|
- $file = request()->image;
|
|
|
- $filename = time() . '_' . $file->getClientOriginalName();
|
|
|
+ // === IMAGE HANDLING SECTION ===
|
|
|
+ Log::info('=== IMAGE HANDLING START ===');
|
|
|
|
|
|
- if (! File::exists(public_path() . "/files/news"))
|
|
|
- File::makeDirectory(public_path() . "/files/news");
|
|
|
+ // Check for filename from crop
|
|
|
+ if (isset($input["filename"]) && $input["filename"] != '') {
|
|
|
+ Log::info('Filename from crop found:', [$input["filename"]]);
|
|
|
|
|
|
- $path = public_path('files/news');
|
|
|
- request()->image->move($path, $filename);
|
|
|
- $input["image"] = $filename;
|
|
|
- Log::info('Main image uploaded:', [$filename]);
|
|
|
- } else {
|
|
|
- if (isset($input["filename"])) {
|
|
|
+ // Verify file exists
|
|
|
+ $filePath = public_path('files/news/' . $input["filename"]);
|
|
|
+ $fileExists = file_exists($filePath);
|
|
|
+
|
|
|
+ Log::info('Crop file verification:', [
|
|
|
+ 'filename' => $input["filename"],
|
|
|
+ 'full_path' => $filePath,
|
|
|
+ 'exists' => $fileExists,
|
|
|
+ 'is_readable' => $fileExists ? is_readable($filePath) : false,
|
|
|
+ 'file_size' => $fileExists ? filesize($filePath) : 0
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($fileExists) {
|
|
|
$input["image"] = $input["filename"];
|
|
|
- Log::info('Using existing filename:', [$input["filename"]]);
|
|
|
+ Log::info('Using cropped image filename:', [$input["filename"]]);
|
|
|
+ } else {
|
|
|
+ Log::error('Cropped image file does not exist!');
|
|
|
}
|
|
|
}
|
|
|
+ // Check for direct file upload
|
|
|
+ elseif ($request->hasFile('image')) {
|
|
|
+ Log::info('Direct image upload detected');
|
|
|
+
|
|
|
+ $file = $request->file('image');
|
|
|
+ Log::info('Upload file details:', [
|
|
|
+ 'original_name' => $file->getClientOriginalName(),
|
|
|
+ 'size' => $file->getSize(),
|
|
|
+ 'mime_type' => $file->getMimeType(),
|
|
|
+ 'is_valid' => $file->isValid()
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($file->isValid()) {
|
|
|
+ $filename = time() . '_' . $file->getClientOriginalName();
|
|
|
+
|
|
|
+ if (!File::exists(public_path() . "/files/news")) {
|
|
|
+ Log::info('Creating news directory');
|
|
|
+ File::makeDirectory(public_path() . "/files/news");
|
|
|
+ }
|
|
|
+
|
|
|
+ $path = public_path('files/news');
|
|
|
+ $file->move($path, $filename);
|
|
|
+ $input["image"] = $filename;
|
|
|
+
|
|
|
+ Log::info('Direct image uploaded successfully:', [
|
|
|
+ 'filename' => $filename,
|
|
|
+ 'path' => $path . '/' . $filename
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ Log::error('Invalid file upload');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Log::info('No image provided (neither crop nor direct upload)');
|
|
|
+ }
|
|
|
+
|
|
|
+ Log::info('Final image value:', [$input["image"] ?? 'none']);
|
|
|
+ Log::info('=== IMAGE HANDLING END ===');
|
|
|
|
|
|
// Handle additional images
|
|
|
for ($i = 1; $i <= 5; $i++) {
|
|
|
- if (isset($input["image" . $i])) {
|
|
|
+ if ($request->hasFile("image" . $i)) {
|
|
|
Log::info("Processing image{$i} upload");
|
|
|
- $file = $input["image" . $i];
|
|
|
- $filename = time() . '_' . $file->getClientOriginalName();
|
|
|
+ $file = $request->file("image" . $i);
|
|
|
+ $filename = time() . '_' . $file->getClientOriginalName();
|
|
|
|
|
|
- if (! File::exists(public_path() . "/files/news"))
|
|
|
+ if (!File::exists(public_path() . "/files/news"))
|
|
|
File::makeDirectory(public_path() . "/files/news");
|
|
|
|
|
|
$path = public_path('files/news');
|
|
|
- $input["image" . $i]->move($path, $filename);
|
|
|
+ $file->move($path, $filename);
|
|
|
$input["image" . $i] = $filename;
|
|
|
Log::info("Image{$i} uploaded:", [$filename]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Handle PDF
|
|
|
- if (request()->pdf) {
|
|
|
+ if ($request->hasFile('pdf')) {
|
|
|
Log::info('Processing PDF upload');
|
|
|
- $file = request()->pdf;
|
|
|
- $filename = time() . '_' . $file->getClientOriginalName();
|
|
|
+ $file = $request->file('pdf');
|
|
|
+ $filename = time() . '_' . $file->getClientOriginalName();
|
|
|
|
|
|
- if (! File::exists(public_path() . "/files/news"))
|
|
|
+ if (!File::exists(public_path() . "/files/news"))
|
|
|
File::makeDirectory(public_path() . "/files/news");
|
|
|
|
|
|
$path = public_path('files/news');
|
|
|
- request()->pdf->move($path, $filename);
|
|
|
+ $file->move($path, $filename);
|
|
|
$input["pdf"] = $filename;
|
|
|
Log::info('PDF uploaded:', [$filename]);
|
|
|
}
|
|
|
|
|
|
// Date processing
|
|
|
$final_date = null;
|
|
|
- if ($input["date"] != '') {
|
|
|
+ if (isset($input["date"]) && $input["date"] != '') {
|
|
|
list($dt, $time) = explode(" ", $input["date"]);
|
|
|
list($day, $month, $year) = explode("/", $dt);
|
|
|
$final_date = $year . "-" . $month . "-" . $day . " " . $time;
|
|
|
@@ -298,16 +347,29 @@ class NewsController extends Controller
|
|
|
$input["breaking_news"] = isset($input["breaking_news"]) ? ($input["breaking_news"] == 'on' ? true : false) : false;
|
|
|
$input["no_social"] = isset($input["no_social"]) ? ($input["no_social"] == 'on' ? true : false) : false;
|
|
|
|
|
|
- Log::info('Checkbox values:', [
|
|
|
- 'homepage' => $input["homepage"],
|
|
|
- 'live' => $input["live"],
|
|
|
- 'breaking_news' => $input["breaking_news"],
|
|
|
- 'no_social' => $input["no_social"]
|
|
|
- ]);
|
|
|
-
|
|
|
+ Log::info('Final input data before saving:', $input);
|
|
|
Log::info('About to create news record');
|
|
|
+
|
|
|
$news = News::create($input);
|
|
|
- Log::info('News created with ID:', [$news->id]);
|
|
|
+ Log::info('News created successfully:', [
|
|
|
+ 'id' => $news->id,
|
|
|
+ 'title' => $news->title,
|
|
|
+ 'image' => $news->image,
|
|
|
+ 'created_at' => $news->created_at
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // Verify the image was saved correctly
|
|
|
+ if ($news->image) {
|
|
|
+ $savedImagePath = public_path('files/news/' . $news->image);
|
|
|
+ $imageExists = file_exists($savedImagePath);
|
|
|
+
|
|
|
+ Log::info('Saved news image verification:', [
|
|
|
+ 'image_field' => $news->image,
|
|
|
+ 'full_path' => $savedImagePath,
|
|
|
+ 'exists' => $imageExists,
|
|
|
+ 'size' => $imageExists ? filesize($savedImagePath) : 0
|
|
|
+ ]);
|
|
|
+ }
|
|
|
|
|
|
// Handle publish action
|
|
|
if (isset($input['publish'])) {
|
|
|
@@ -320,21 +382,21 @@ class NewsController extends Controller
|
|
|
if ($final_date <= date("Y-m-d H:i:s")) {
|
|
|
Log::info('Date is not in future, processing positions');
|
|
|
|
|
|
- if ($input["section_position"] != '') {
|
|
|
+ if (isset($input["section_position"]) && $input["section_position"] != '') {
|
|
|
Log::info('Processing section position:', [$input["section_position"]]);
|
|
|
$s = Section::findOrFail($input["section_id"]);
|
|
|
$s[$input["section_position"]] = $news->id;
|
|
|
$s->save();
|
|
|
$news->section_position = '';
|
|
|
}
|
|
|
- if ($input["region_1_position"] != '') {
|
|
|
+ if (isset($input["region_1_position"]) && $input["region_1_position"] != '') {
|
|
|
Log::info('Processing region_1 position:', [$input["region_1_position"]]);
|
|
|
$s = Section::findOrFail($input["region_1_id"]);
|
|
|
$s[$input["region_1_position"]] = $news->id;
|
|
|
$s->save();
|
|
|
$news->region_1_position = '';
|
|
|
}
|
|
|
- if ($input["region_2_position"] != '') {
|
|
|
+ if (isset($input["region_2_position"]) && $input["region_2_position"] != '') {
|
|
|
Log::info('Processing region_2 position:', [$input["region_2_position"]]);
|
|
|
$s = Section::findOrFail($input["region_2_id"]);
|
|
|
$s[$input["region_2_position"]] = $news->id;
|
|
|
@@ -367,7 +429,7 @@ class NewsController extends Controller
|
|
|
}
|
|
|
|
|
|
// Handle homepage position
|
|
|
- if ($input["homepage_position"] != '' && $news->online) {
|
|
|
+ if (isset($input["homepage_position"]) && $input["homepage_position"] != '' && $news->online) {
|
|
|
Log::info('Processing homepage position:', [$input["homepage_position"]]);
|
|
|
$home = Home::first();
|
|
|
if ($home != null) {
|
|
|
@@ -404,6 +466,7 @@ class NewsController extends Controller
|
|
|
|
|
|
Log::info('No specific action, redirecting to news.index');
|
|
|
return redirect()->route('news.index')->with('success', 'News created successfully');
|
|
|
+
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('=== ERROR IN STORE METHOD ===');
|
|
|
Log::error('Error message:', [$e->getMessage()]);
|