diff --git a/app/Http/Controllers/PlanController.php b/app/Http/Controllers/PlanController.php index 495cb18..474a66f 100644 --- a/app/Http/Controllers/PlanController.php +++ b/app/Http/Controllers/PlanController.php @@ -62,9 +62,13 @@ class PlanController extends Controller ->cooldown($expiresAt) ->record(); - $options1 = $this->unserializeOptions($plan->packet1_options); - $options2 = $this->unserializeOptions($plan->packet2_options); - $options3 = $this->unserializeOptions($plan->packet2_options); + // $options1 = $this->unserializeOptions($plan->packet1_options); + // $options2 = $this->unserializeOptions($plan->packet2_options); + // $options3 = $this->unserializeOptions($plan->packet2_options); + $options1 = $plan->packet1_options; + $options2 = $plan->packet2_options; + $options3 = $plan->packet2_options; + return view('plan/show', [ 'plan' => $plan, diff --git a/app/Models/Plan.php b/app/Models/Plan.php index 708d131..b718016 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -57,7 +57,9 @@ class Plan extends Model implements Viewable $result = []; for ($i = 1; $i <= $this->packets_count; $i++) { $key = "packet" . $i . "_options"; - $data = $this->unserializeOptionsObj($this->$key); + + // $data = $this->unserializeOptionsObj($this->$key); + $data = $this->$key; if (!is_null($data)) { $result = array_merge($result, data_get($data, "items", [])); } @@ -68,7 +70,8 @@ class Plan extends Model implements Viewable public function types(): Attribute { - $data = $this->unserializeOptionsArr($this->type); + // $data = $this->unserializeOptionsArr($this->type); + $data = $this->type; return new Attribute( get: fn () => array_keys($data), @@ -80,7 +83,9 @@ class Plan extends Model implements Viewable $result = 0; for ($i = 1; $i <= $this->packets_count; $i++) { $key = "packet" . $i . "_options"; - $data = $this->unserializeOptionsObj($this->$key); + // dd($this->$key); + // $data = $this->unserializeOptionsObj($this->$key); + $data = $this->$key; if (!is_null($data)) { $curPrice = (int)data_get($data, "price", 0); $result = $curPrice > $result ? $curPrice : $result ; diff --git a/database/factories/PlanFactory.php b/database/factories/PlanFactory.php index 9220ba6..a87d4b4 100755 --- a/database/factories/PlanFactory.php +++ b/database/factories/PlanFactory.php @@ -19,6 +19,7 @@ class PlanFactory extends Factory */ public function definition(): array { + $faker = \Faker\Factory::create(); $this->faker->addProvider(new Restaurant($faker)); @@ -37,11 +38,13 @@ class PlanFactory extends Factory ]; Storage::fake('plans'); + $file = UploadedFile::fake()->image('plan.png'); + $fileLocalPath = $file->store('plans', 'public'); return [ 'name' => $this->faker->foodName(), // 'image' => UploadedFile::fake()->image('plans/Photo_C.png'), - 'image' => UploadedFile::fake()->image('plan.png'), + 'image' => $fileLocalPath, 'duration' => $this->faker->randomElement([7, 14,21]), 'state' => $this->faker->randomElement(['active', 'draft', 'archived']), 'type' => $typeBody, diff --git a/database/seeders/PlanAuthor.php b/database/seeders/PlanAuthor.php new file mode 100644 index 0000000..805280a --- /dev/null +++ b/database/seeders/PlanAuthor.php @@ -0,0 +1,27 @@ + 0 && Plan::count() > 0) { + Plan::each( function ($plan) { + User::inRandomOrder() + ->first() + ->author_of_plans() + ->attach($plan->id); + }); + } + } +} diff --git a/resources/views/plan/show.blade.php b/resources/views/plan/show.blade.php index 29a1f2d..473264f 100644 --- a/resources/views/plan/show.blade.php +++ b/resources/views/plan/show.blade.php @@ -2,6 +2,10 @@ @php $author = $plan->author()->first(); $authorPhoto = Storage::url($author->profile_photo_path); + if(is_null($author->profile_photo_path)) { + $authorPhoto =$author->profile_photo_url; + } + $image = Storage::url($plan->image); $planViewsCount = views($plan)->unique()->count(); @endphp