NuOrder's avatar

NuOrder started a new conversation+100 XP

1w ago

Hello,

php artisan inertia:start-ssr stop working after update to version Inertia 3.0.2

when I try to run: inertia:start-ssr I got error:

"Inertia SSR bundle not found. Set the correct Inertia SSR bundle path in your inertia.ssr.bundle config."

what is wrong with? :|

NuOrder's avatar

NuOrder liked a comment+100 XP

1w ago

The issue is not that promo_price and price are in course_attributes. The main problem is that once you join() course_attributes inside the eager-loaded courses query, Eloquent may stop hydrating SchoolCourse properly unless you explicitly select the base table columns.

That is why relations like calendar, tags, and attributes appear to break.

The fix is to keep the join for sorting, but add:

->select('school_courses.*')

and sort with:

->orderByRaw('COALESCE(course_attributes.promo_price, course_attributes.price) ASC')

Then by logic, the eager-loaded courses query should look more like this:

->with([
    'courses' => function ($q) use ($attr) {
        $q->select('school_courses.*')
            ->where('active', '>=', 1)
            ->whereHas('tags', function ($tagQuery) use ($attr) {
                $tagQuery->whereIn('tags.id', [
                    $attr['attributes']['category'],
                    $attr['attributes']['course_type'],
                ]);
            }, '=', 2)
            ->leftJoin('course_attributes', 'course_attributes.school_course_id', '=', 'school_courses.id')
            ->orderByRaw('COALESCE(course_attributes.promo_price, course_attributes.price) ASC')
            ->with(['attributes', 'calendar', 'tags.category:id,name']);
    }
])

If you also want to sort the parent schools by the cheapest matching course, that is better done with a subquery using MIN(COALESCE(...)), not by moving the price columns onto school_courses.

So I would not refactor the schema just to make sorting easier. The current structure can handle it; the query just needs to be adjusted.

Also, sorting parents in PHP collections works for small datasets, but for proper DB-level sorting and pagination, a subquery is the cleaner approach.

NuOrder's avatar

NuOrder started a new conversation+100 XP

1mo ago

When I use component:

and try to compile project nom run build:ssr then run: php artisan inertia:start-ssr

viewing webpage with disabled javascript shutdown inertia SSR server with error:

resolveComponent=fn<resolveComponent> ... >
at <App>
file:///project/node_modules/@inertiajs/vue3/dist/index.esm.js:1724 this.observer = new IntersectionObserver(
^

ReferenceError: IntersectionObserver is not defined
at Proxy.registerObserver (file:///project/node_modules/@inertiajs/vue3/dist/index.esm.js:1724:27)

how can I render SSR page with using "WhenVisible" component ?

Here is my SSR.js config file:

import '@/../css/core.css' import '@/../css/app.scss' import {createInertiaApp, Head, Link, WhenVisible} from '@inertiajs/vue3' import {resolvePageComponent} from 'laravel-vite-plugin/inertia-helpers'; import createServer from '@inertiajs/vue3/server' import {renderToString} from '@vue/server-renderer' import {createSSRApp, h} from 'vue' import {createPinia} from 'pinia' import Layout from '@/shared/Layout.vue'

const pina = createPinia() createServer(page => createInertiaApp({ page, render: renderToString, resolve: name => { const page = resolvePageComponent(./Pages/${name}.vue, import.meta.glob('./Pages/**/*.vue')); page.then((module) => module.default.layout = module.c || Layout) return page }, setup({App, props, plugin}) { return createSSRApp({ render: () => h(App, props), }).use(plugin).use(pina).component('Head', Head).component('Link', Link).component('WhenVisible', WhenVisible) } }), {cluster: false} )

NuOrder's avatar

NuOrder wrote a reply+100 XP

1mo ago

Unfortunately this code:

$schools = School::whereHas('courses', function ($course_query) use ($attr) { $course_query->where('active', '>=', 1) ->whereHas('tags', function ($query) use ($attr) { $query->whereIn('id', [ $attr['attributes']['category'], $attr['attributes']['course_type'] ]); }, '=', 2); }) // Eager-load the sortedCourses relationship we defined ->with(['sortedCourses' => function($q) use ($attr) { // you could add more filters if needed here, for tags $q->with(['calendar', 'tags.category:id,name', 'attributes']); }]) ->get();

does not work properly because it's return sorted ASC "sortedCourses" relation but without relation: $q->with(['calendar', 'tags.category:id,name', 'attributes']);

I need retrieve "sortedCourses" with other course relation: ->with(['calendar', 'tags.category:id,name',

How can I do that ?

In my opinion it looks like I need to refactor whole logic and move from courses.attributes :

  • price
  • promo_price

to parent "courses" table then I can do it easy like:

$schools->with(['courses' => function($q) { $q->with('attributes', 'calendar', 'last_discount'); $q->orderBy('promo_price) ->orderBy('price') }])

NuOrder's avatar

NuOrder started a new conversation+100 XP

1mo ago

Hello,

Dear community people, this is my first post .. I was looking for answers here and other internet posts and founds some tips but no one works.

I will describe how SQL data works and what I need to do.

  1. Parent table is: "schools"

School model got method:

public function courses(): hasMany { return $this->hasMany(SchoolCourse::class); }

  1. Schools has many "courses" wich Is collect in table name "school_courses"

School_courses model got method:

public function tags(): belongsToMany { return $this->belongsToMany(Tag::class); }

public function calendar(): hasMany { return $this->hasMany(CourseCalendar::class) ->orderByRaw("DATE_FORMAT(startDate,'%Y-%m-%d') asc"); }

public function attributes(): hasOne { return $this->hasOne(CourseAttribute::class); }

in attributes we stores values like:

  • price ( price of course )
  • promo_price ( discounted course price)
  1. I need to retrieve all Schools "withWhereHas" courses with specific tags ID matched

a) I need to find only schools wich got courses as 'active' >= 1,

b) I need get all courses in every school sorted by promo_price ASC, (if promo_price not exist) by price ASC

c) I need also sorted Schools wich got lowest promo_price (if promo_price not exist) or price ASC

so mainly I do it like this:

$schools = School::query();

// $attr <-- is parsed POST data from search engine like this: $attr = request()->validate([....])

$schools->withWhereHas('courses', function ($course_query) use ($attr) { $course_query->where('active', '>=', 1) ->whereHas('tags', function ($query) use ($attr) { $query->whereIn('id', [$attr['attributes']['category'], $attr['attributes']['course_type']]); }, '=', 2)

// I try to use JON to make a chance to order courses by promo_price & price ASC

  $course_query->join('course_attributes', 'school_courses.id', '=', 'course_attributes.school_course_id')
    ->orderBy('promo_price')
    ->orderBy('price')
    ->with([' calendar', 'tags.category:id,name']);
});

When I make this join: $course_query->join('course_attributes', 'school_courses.id', '=', 'course_attributes.school_course_id')

Query result brake other eloquent methods: ->with([' calendar', 'tags.category:id,name']); In response there is no:

  • schools[0]->courses[0]->calendar
  • schools[0]->courses[0]->tags

but I see "price", "promo_price" and other parameters from "course_attributes" table

So my question is how can I retrieve all Schools wich got courses as "active" >=1 and this courses will be sorted by promo_price ASC , price ASC and then parents ( Schools) will be also sorted according to his courses lowest promo_price or price ?

I try also something strange (from internet):

$data = $schools->with([' calendar', 'tags.category:id,name', 'attributes' => fn($query) => { $query->orderBy('promo_price', 'ASC') ->orderBy('price', 'ASC') ])->get())->sortBy(function ($school, $key) { return $school->courses->min->attributes->price; })->values()

<-- but sorting by price ASC not works properly :(