Giter Club home page Giter Club logo

Comments (8)

duncanmcclean avatar duncanmcclean commented on July 18, 2024 1

Thanks for doing some digging!

Runway's RunwayRoutes trait contains a slug() method (which is required by Statamic's routing contracts).

The slug method attempts to get the current slug for the model, using Eloquent's getAttribute method. Since, it can't find a value for slug on the model, it finds that there's a slug() method on the model and tries to use that instead. That's where the infinite loop happens.

We do need the slug method in the RunwayRoutes method or the feature wouldn't work at all. However, it obviously needs to be re-worked to avoid the infinite loop. I'll have a think about the best way to fix this 🤔

from runway.

duncanmcclean avatar duncanmcclean commented on July 18, 2024

Are you using the {{ nocache }} tag anywhere?

from runway.

cworreschk avatar cworreschk commented on July 18, 2024

No, I'm not using any {{ nocache }} tag.

I'm using Laravel Herd and installed with the statamic/cli a fresh new Statamic project. The only installed Addon is statamic-rad-pack/runway.

Without configurating anything I've created a new Model with only these lines of code:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use StatamicRadPack\Runway\Routing\Traits\RunwayRoutes;
use StatamicRadPack\Runway\Traits\HasRunwayResource;

class Dog extends Model {
    use HasRunwayResource, RunwayRoutes;
}

The runway configuration has only one resource:

<?php

return [
    'resources' => [
        App\Models\Dog::class => [
            'name'        => 'Dogs',
            'route'       => '/dogs/{{ slug }}',
            'template'    => 'dogs/show',
        ],
    ],
    'disable_migrations' => true,
];

I open Tinker straight after that:
image

After I've removed the RunwayRoutes trait, I'm getting a null as expected:
image

from runway.

duncanmcclean avatar duncanmcclean commented on July 18, 2024

What does your migration look like? Do you have a slug column?

from runway.

cworreschk avatar cworreschk commented on July 18, 2024

In my real project I do have a slug column, but here in my example with the freshly created Statamic project and the Dog class, there is no migration. But in both cases I'm getting the exception.

from runway.

duncanmcclean avatar duncanmcclean commented on July 18, 2024

Do you get the same error when creating models with the Dog::create([]) syntax?

from runway.

cworreschk avatar cworreschk commented on July 18, 2024

If I try to create the Dogmodel with Dog::create([]) then I get a different error:
image

I've tested it now with Laravel Sail, to check if Laravel Herd is the problem. But the same exception 😞

It's really strange. Especially as it's a completely fresh Statamic installation.

from runway.

cworreschk avatar cworreschk commented on July 18, 2024

After some tests I found out that the exception only occurs if the slug is unset. If it has a value, everything's fine.

In my case the user has the possibility to set the slug manually. If it's not set, in the life cycle event creating the value is generated by another field, e.g. title.

But the content of the slug field cannot be checked, because if it's empty, the exception is thrown.

I have to use this workaround: Get all attributes with toArray() or getAttributes() and check if the slug is set 🙃

from runway.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.