Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

garrettmassey's avatar

Nova API route returns 404 response

On this project, the Address model has several belongsTo relationships to other models like City and County. In the Nova Address Resource, using the BelongsTo field for City on the address works, and the user is able to select the city from the dropdown, or even search or create a new City resource inline.

However, the other BelongsTo fields all return a 404 error on the API when it comes to get the data to populate the select field.

GET    
https://example.test/nova-api/addresses/associatable/county?first=false&search=Berna&withTrashed=false&viaResource=clients&viaRelationship=primaryAddress&component=belongsto.belongs-to-field.county&dependsOn=eyJjb3VudHkiOiIifQ%3D%3D&editing=true&editMode=create
404 (Not Found)

Address.php Nova Resource fields:

public function fieldsForCreate(NovaRequest $request)
{
    return [
        Text::make('Address Line 1', 'address_line_1')
            ->size('w-1/3')
            ->required(),

        Text::make('Address Line 2', 'address_line_2')
            ->size('w-1/3')
            ->nullable(),

        Text::make('Cross Streets')
            ->size('w-1/3')
            ->nullable(),
		
		//This works just fine, you can search for a city
		//and select the results
        BelongsTo::make('City', 'city', City::class)
            ->required()
            ->searchable()
            ->showCreateRelationButton()
            ->size('w-1/2'),

		//this does NOT work. When you search for a county,
		//the console shows a 404 error on the API
        BelongsTo::make('County', 'county', County::class)
            ->required()
            ->searchable()
            ->size('w-1/2'),

County Fields:

public function fields(NovaRequest $request): array
{
    return [
        Text::make('Name', 'name')->sortable(),
        ...AttributeStatusBadge::make($this->resource),
        ...Metadata::make($this->resource),
    ];
}

I know the relationship works because I am able to view the counties for existing addresses on the resource Index page, and I am able to access the relationship via tinker and unit tests. But I can't figure out why the Nova API is returning 404 on the County BelongsTo relationship field, but not the City field.

0 likes
0 replies

Please or to participate in this conversation.