Giter Site home page Giter Site logo

folio's Introduction

Laravel Logo

Build Status Total Downloads Latest Stable Version License

About Laravel

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:

Laravel is accessible, powerful, and provides tools required for large, robust applications.

Learning Laravel

Laravel has the most extensive and thorough documentation and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.

You may also try the Laravel Bootcamp, where you will be guided through building a modern Laravel application from scratch.

If you don't feel like reading, Laracasts can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.

Laravel Sponsors

We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel Partners program.

Premium Partners

Contributing

Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the Laravel documentation.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [email protected]. All security vulnerabilities will be promptly addressed.

License

The Laravel framework is open-sourced software licensed under the MIT license.

folio's People

Contributors

aaezha avatar ahmedash95 avatar cleptric avatar crynobone avatar datlechin avatar driesvints avatar inmanturbo avatar jessarcher avatar jubeki avatar komtcho avatar michaelnabil230 avatar morrislaptop avatar nunomaduro avatar shuvroroy avatar stayallive avatar stewartmuhanuzi avatar taylorotwell avatar timacdonald avatar xico2k avatar zupolgec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

folio's Issues

Top level components are not receiving parameter values

Folio Version

1.0.0-beta.1

Laravel Version

10.16.1

PHP Version

8.1

Description

Not sure if this is a bug or not, but if a view component is used inside a Folio page as the 'top level' component, e.g. as a layout component, parameters do not get passed to the component. But it does get passed through once it's nested inside another div.

E.g. this doesn't pass the title parameter:

<x-app-layout title="Videos">

   ...

</x-app-layout>

But this does:

<div>
    <x-app-layout title="Videos">
        
        ...

    </x-app-layout>
</div>

Steps To Reproduce

  1. Create a component that accepts a parameter and outputs it in the component.
  2. Use the component inside a Folio page as the top-level component. Pass along the parameter.
  3. Result: the parameter's value is not passed to the component.
  4. Now, in the Folio page, wrap the component with div tags.
  5. Refresh the output.
  6. Result: the parameter's value is now passed to the component.

Register named routes

Hello,

I couldn't find a way to implement named routes in Folio.
That would be a pretty important feature to me, since I can't generate links to Folio pages via the route() helper.

I checked the output of "artisan route:list" and it doesn't seem like it is registering routes at all?
Edit: Ah ok, all under one route, I see.

Thanks!

Use Folio and controllers for the same parent url

I think it would be nice to use Folio base routing and the controller based routing for the same parent route.

Example

The url /products is created using Laravel Folio and the route /products/{id} being used with a controller in the web.php file.

On Windows Laravel Folio throws always a PossibleDirectoryTraversal Exception

Folio Version

v1.0.0-beta.1

Laravel Version

v10.16.1

PHP Version

8.1.10

Description

I'm using Laravel with Laragon on Windows, every time I try to load some blade file in the default Folio folder ('/view/pages') Laravel throws a PossibleDirectoryTraversal Exception.

Looking in the sources of the package, the problem seems located in vendor/laravel/folio/src/Pipeline/EnsureNoDirectoryTraversal.php at row 22:

if (! Str::of(realpath($view->path))->startsWith($state->mountPath.'/')) { throw new PossibleDirectoryTraversal; }

Using dd() the result of realpath($view->path) has a different ending char than $state->mountPath.'/'

realpath($view->path) => C:\laragon\www\filamentv3\resources\views\pages\index.blade.php"
$state->mountPath.'/' => "C:\laragon\www\filamentv3\resources\views\pages/"

Steps To Reproduce

  1. Install Laravel Folio
  2. Delete default route
  3. Create a page with php artisan make:folio index
  4. Try to load the the folio route with the browser

Route model binding for a model called "Event" throws a "does not implement the UrlRoutable interface" error

Folio Version

1.0.0-beta.4

Laravel Version

10.18.0

PHP Version

8.1

Description

When I use folio with route model binding for a model named Event, it thows this error:

Folio route attempting to bind to class [Event], but it does not implement the UrlRoutable interface.

This doesn't happen for my other models. And it doesn't happen when I specifically tells it where the model is using [.App.Models.Event].blade.php as the filename.

I'm wondering whether it's picking up another Event class from somewhere else?

Steps To Reproduce

Create a model called Event.

Create the folio page: php artisan make:folio "events/[Event]"

Access the page with /events/[event-id]

Error is thrown.

Session not set in Global Scope

Folio Version

1.0.0

Laravel Version

10.20.0

PHP Version

8.2.4

Description

Folio returns a 404 when using a session within a Global Scope in an Eloquent model.
session('test') returns null; in plain Laravel it returns the actual session data.

Steps To Reproduce

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Database\Eloquent\Builder;

class Test extends Model
{
    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('test', fn (Builder $builder) => $builder->where('test', session('test')));
    }
}
// folio/[Test]/edit.blade.php

{{ $test->id }}

Command "folio:make" is not defined

Folio Version

v1.0.0-beta.1

Laravel Version

10.16.0

PHP Version

8.2.8

Description

โฏ laravel (production) โœ˜ php artisan folio:make user/profile

   ERROR  Command "folio:make" is not defined. Did you mean one of these?

  โ‡‚ folio:install
  โ‡‚ folio:list

Steps To Reproduce

I followed the steps in the README

composer require laravel/folio:^1.0@beta
php artisan folio:install

Could other files work eg *.blade.md or *.blade.html

Firstly - I think this is brilliant for super simple sites that don't need too much complexity on the routing front.

As I said in the title - could other file types work?

That would be awesome.

Priority: NTH (Nice to have)

Wildcard route collision

Folio Version

1.1.3

Laravel Version

10.22.0

PHP Version

8.2.3

Description

Hello team,
Thanks for the great job. Laravel Folio is really amazing.

Thus, I don't know if I should create a new issue for it has almost the same topic.
I still have some routes (files) that are not accessible due to collision with another wildcard route.

image

The route /create is not reachable. When trying to access it, Folio keeps using /{id} and just passes the term create as $id.

Steps To Reproduce

Create a new Laravel project using Folio and the following tree structure (without implicit model binding).

image

Empty segments in multi-segment wildcard views are not possible

Folio Version

1.1.3

Laravel Version

10.4.1

PHP Version

8.2.11

Description

Consider the following view: resources/views/pages/users/[...ids].blade.php

<ul>
    @forelse(\App\Models\User::whereIn('id', $ids)->get() as $user)
       <li>{{ $user->email }}</li>
    @empty
       <li>No users available</li>
    @endforelse
</ul>

When you browse to /users you might expect to see 'No users available', however instead you will get 404.

Steps To Reproduce

Install folio and paste the above contents into resources/views/pages/users/[...ids].blade.php, then browse to '/users' in your application

Nested model route binding keeps disabling views

Folio Version

1.1.3

Laravel Version

10.28.0

PHP Version

8.2.10

Description

When using Folio I'm unable to display a create page when a subfolder [id] exists.
The index page is however correctly displayed.

Steps To Reproduce

Here's what my pages folder look like:
Captura de tela 2023-10-10 200036

And here's what php artisan folio:list shows:
Captura de tela 2023-10-10 200443

The admin/properties/index.blade.php works perfectly
The admin/properties/[id]/index.blade.php works perfectly
The admin/properties/[id]/edit.blade.php works perfectly
The admin/properties/create.blade.php ERROR, it is working as admin/properties/[id]/index.blade.php, as I show below:
Captura de tela 2023-10-10 200943

If I remove the "admin/properties/[id]" folder the create page is displayed.

Illegal characters on Windows for model binding

Folio Version

1.0.0-beta.4

Laravel Version

10.18.0

PHP Version

8.2.8

Description

When trying to create a page named [Model:key].blade.php for model binding, Windows won't allow ":" in file names.

I don't know if we could use an alternate character on Windows, or if we could just add another character with the same effect but that would be valid on Windows (so Linux users would have 2 ways of writing it).

On Windows, these are illegal characters in filenames: \ / : * ? " < > |

So I guess we could use characters that are illegal in PHP classes and function names such as: ! @ # $ % & ; , . ~

I'm sorry because I love the ":" separator, it's very clear and nice. Just unusable on Windows.

Steps To Reproduce

On Windows

$ php artisan make:folio things/[Thing:number]

   INFO  Page [C:\laragon\www\application\resources\views\pages/things/[Thing:number].blade.php] created successfully.

Creates an empty folder named "thing" instead.

Sane Errors

The three main struggles with folio (and volt) are intellisense, static analysis and error reporting.

The first two depend on your dev environment, and ide's and lsp's are continuing to evolve to help with that.

Error reporting is still a problem though. Errors often aren't caught before the blade view is compiled, and errors aren't caught at "compile time" (I'm referring to the blade compiler here).

If the error occurs in the template, we often have no idea where in the template it occurred. I find myself struggling to get good reporting and spending a lot of time in tools like spatie/ray or just ddd()ing all the time to figure things out.

It's nice to have a quick feedback loop, but how can we improve the quality of the feedback? Are there some best practices that might be useful to have in the docs? Can we pass some kind of debug flags to the blade compiler from folio views, maybe send line numbers through for the @php code blocks?

PS:
I know that a fair answer to this is: "If you want better stack trace and language support use a psr-4 controller instead of folio, and do exhaustive error checking before returning your view". I'm just shaking the tree here to see if anything good or helpful falls out.

Automatically route & render markdown files

Originally from a tweet: https://twitter.com/snellingio/status/1688646569157939201?s=20

Followed up with a pitch inside the internals discord.

Putting this here as a placeholder for a PR.

Currently: To render a markdown file, you need to wrap in a .blade.php. So, to render something like a post, or a terms of service, etc, you end up needing a blade file.

pages
โ””โ”€โ”€ terms-of-service.blade.php

And the content would look something like

<x-layouts.app title="Terms of Service">
<x-markdown>
# Terms of Service

[...]
</x-markdown>
</x-layouts.app>

What I really want to do is just have a markdown file.

pages
โ””โ”€โ”€ terms-of-service.md

And the content could use YAML front matter (as is the standard in other page / routing frameworks) to pass in blade options. The actual content would go into the $slot variable as one would expect.

---
component: x-layouts.app
title: Terms of Service
---

# Terms of Service

[...]

Unsure if it would be best named as component or layout but that's all I would really need to wrap it all up.

This has a lot of benefits, from cross-platform drag and drop, to editor preview rendering!

Add query parameters to named routes.

Currently, named routes don't support passing in query parameters to route, which doesn't provide 100% feature parity with native named routes. I noticed this while updating my test app tangerine to support named routes.

I also confirmed this by updating the feature parity test and appending a query parameter.

test('feature parity', function () {
    Route::get('/posts/{lowerCase}/{UpperCase}/{podcast}/{user:email}/show', function (
        string $id,
        string $upperCase,
        Podcast $podcast,
        User $user) {
        //
    })->name('users.regular');

    $parameters = [
        'lowerCase' => 'lowerCaseValue',
        'upperCase' => 'UpperCaseValue',
        'podcast' => Podcast::first(),
        'user' => User::first(),
        'query' => 'string',
    ];

    $expectedRoute = '/posts/lowerCaseValue/UpperCaseValue/1/[email protected]/show?query=string';

    $route = route('users.regular', [
        'lowerCase' => 'lowerCaseValue',
        'UpperCase' => 'UpperCaseValue',
        'podcast' => Podcast::first(),
        'user' => User::first(),
        'query' => 'string',
    ], false);

    expect($route)->toBe($expectedRoute);

    $route = route('posts.show', $parameters, false);

    expect($route)->toBe($expectedRoute);
});

This fails the expectation for Folio's named routes, but not for the native named routes:

 FAILED  Tests\Feature\NameTest > feature parity                                                                                             
  Failed asserting that two strings are identical.
  -'/posts/lowerCaseValue/UpperCaseValue/1/[email protected]/show?query=string'
  +'/posts/lowerCaseValue/UpperCaseValue/1/[email protected]/show'
  

  at tests/Feature/NameTest.php:103
     99โ–•     expect($route)->toBe($expectedRoute);
    100โ–• 
    101โ–•     $route = route('posts.show', $parameters, false);
    102โ–• 
  โžœ 103โ–•     expect($route)->toBe($expectedRoute);
    104โ–• });
    105โ–• 
    106โ–• test('model route binding wrong column', function () {
    107โ–•     $parameters = [

  1   tests/Feature/NameTest.php:103


  Tests:    1 failed (2 assertions)
  Duration: 0.08s

This is used internally by Laravel, say password reset when generating the URL for the notification, which adds the users' email as a query parameter. Using a regular named route adds the query parameter, while Folio doesn't.

Would be great if Folio also supported adding query parameters when generating a URL with route.

package routes

Folio Version

1

Laravel Version

10

PHP Version

8

Description

what is the recommended way of declaring package routes to be handled by folio?

is it like this?:

    public function boot(): void
    {
        Folio::path(base_path('vendor/myname/mypackage/resources/views/pages'))->middleware([
            '*' => [
                //
            ],
        ]);
    }

Steps To Reproduce

see description

Route Caching not possible anymore

Folio Version

1.0.0-beta.3

Laravel Version

v10.17.1

PHP Version

8.2.8

Description

On a fresh laravel application with folio installed, it is no longer possible to cache the routes.

The following error occurs.

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 606208 bytes) in vendor/laravel/framework/src/Illuminate/Routing/Route.php on line 1343
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 480

Steps To Reproduce

laravel new folio-test
cd folio-test
composer require laravel/folio:^1.0@beta
php artisan folio:install
php artisan route:cache

Generated route names are prone to collision

Coming from ded968e#commitcomment-123084859:

10 hexadecimal characters have an entropy of 40 bits. That is very low (for perspective, only barely above CRC32, which is very prone to collision).
I would suggest to slightly raise the number of characters.

(see the 2nd table at https://en.wikipedia.org/wiki/Password_strength#Random_passwords)

Excerpt from the mentioned table:

Entropy Hexadecimal chars
8 bits 2
32 bits 8
40 bits 10
64 bits 16
80 bits 20
96 bits 24
128 bits 32
160 bits 40
192 bits 48
224 bits 56
256 bits 64

As you can see at the bottom of this article, 32-bit is insanely low:

Hash Collision Probabilities

Therefore, I would recommend no less than 16 characters (entropy of 64 bits).

Folio Route Fallback

Reason

I'm building an app that will use Folio and Volt. Because this app does not have an API, I removed the RouteServiceProvider as I think this is unnecessary for this app. By removing the RouteServiceProvider, I lost the ability to create a fallback router, and that caused me to open this feature request.

As Folio's proposal is to offer routes based on files, there are scenarios like this one where we are creating a simple website that doesn't require routes to be created via routes/web.php - also because it loses the sense of using Folio, I believe that it is extremely necessary to create a way to define a fallback - a Folio file that, when it exists, receives all requests that don't match any other Folio route. When the file does not exist, we can then allow a 404 status.

Proposal

The fallback route can match: [].blade.php

Discovery

An ErrorException is thrown when there is a file like pages/[].blade.php at the root of the project. Perhaps the Folio is one step closer to allowing fallback? ๐Ÿค”

CleanShot 2023-08-26 at 7 34 48

Final Words

"Why not only restore RouteServiceProvider to create a route by routes/web.php?"

  • As mentioned above, if Folio's proposal is to offer routes based on files, I think we can have this type of control without depending on the RouteServiceProvider and default routes for that.

Will this work for regular php files?

The view() helper can also be used to reach for plain vanilla (non-blade) .php files. Is there a way to do this with folio as well?

In the case where there may be any reason you want to preserve paths and/or don't need the extra compile step in some views.

EDIT:

I see where '.blade.php' is hard coded in the Match pipeline. Any plans to allow customizing or extending the pipeline, or any interest in a PR to that effect? In fact if the Pipeline and renderer could be extended, I can foresee a wide variety of use cases for other file types as well, including markdown and html.

Route::currentRouteName() for Laravel Folio named route returns 'laravel-folio'

Folio Version

v1.0.0-beta.6

Laravel Version

10.19.0

PHP Version

8.2.3

Description

When using a named route in Laravel Folio the Route::currentRouteName() function returns "laravel-folio" instead of the route name defined in the name function. I'm not sure if this is required for Folio's magic or just unintended.

Steps To Reproduce

  1. create a new Folio page
  2. add a name โ€” e.g. name('about')
  3. the output of Route::currentRouteName() equals "laravel-folio" instead of "about"

domain() works with only one domain.

Folio Version

1.1.5

Laravel Version

10.37.3

PHP Version

8.1.4

Description

Folio::path(resource_path("views/pages/"));
Folio::domain('domain-one.test')->path(resource_path("views/pages/tenants/one"));
Folio::domain('domain-two.test')->path(resource_path("views/pages/tenants/two"));

First and 2nd line is working. but 2nd or any next domain is not working.

foreach($domains as $domain)
{
Folio::domain($domain->domain)->path(resource_path("views/pages/tenants/$domain->slug"));
}

in above code only first domain is working. any next domains are not working

Steps To Reproduce

in FolioServiceProvider

public function boot(): void
    {
        Folio::path(resource_path("views/pages/"));
        Folio::domain('domain-one.test')->path(resource_path("views/pages/tenants/one"));
        Folio::domain('domain-two.test')->path(resource_path("views/pages/tenants/two"));
    }

Problem with subdomain

Folio Version

1.0.0

Laravel Version

10.20

PHP Version

8.2

Description

I'm having this problem when trying to use subdomain following the documentation. Could it be a bug? that is not injecting the subdomain into the blade?

Steps To Reproduce

app/Providers/FolioServiceProvider.php

class FolioServiceProvider extends ServiceProvider
{
    ...
    public function boot(): void
    {
        Folio::path(resource_path('views/pages'))->middleware([
            '*' => [
                //
            ],
        ]);

        Folio::domain('{account}.laravel.docker')
            ->path(resource_path('views/pages/painel'));
    }
    ...    
}

resources/views/pages/painel/index.blade.php

<div class="row">
    <div class="col-md-12">
        <h1 class="page-header">Hello {{$account}} </h1>
    </div>
</div>

Error:
Undefined variable $account

Route Subdomain / Domain

Hi,

Is there way to configure folio for different subdomain grouping like normal route ?

->domain()

allow custom route registrar action for volt

right now when we use folio with volt we must add @volt directive and <x-layouts.app> tag to our full page components, e.g.:

<x-layouts.app>
    @volt
        <h1>hello world</h1>
        <button wire:click="incrementCount">increment count</button>
    @endvolt
</x-layouts.app>

when registering full page components directly with volt, we use the Volt::route method:

Vote::route('/', 'index');

when we do it this way, we do not need to use the @volt directive or the layout tag in our view:

<div>
    <h1>hello world</h1>
    <button wire:click="incrementCount">increment count</button>
</div>

what if we could simply specify this class & method via the Folio registrar?:

Folio::path(resource_path('views/pages'))
    ->action([Volt::class, 'route']) 
    ->middleware([
        '*' => [
            //
        ],
    ]);

or even add a new method to Folio that uses an abstraction for volt:

Folio::path(resource_path('views/pages'))
    ->volt()
    ->middleware([
        '*' => [
            //
        ],
    ]);

this way all our folio pages will be interactive without requiring additional directive, and would also use the default livewire layouts.app component.

i can submit PR if you're interested

thoughts?

Support for Other HTTP Methods

Perhaps this is not the purpose of Folio and therefore this ticket can be closed, but considering that we have different types of HTTP methods, it would be extremely useful if Folio supported this following the following pattern:

contact.blade.php // GET ...
create.post.blade.php
destroy.delete.blade.php
update.put.blade.php

I could suggest that this feature is possible via the FolioServiceProvider, but if Folio intends to support routes via files, IMO the best place would be the prefix shown above.

If I'm totally wrong and the Folio will never support other HTTP methods instead of GET, then shouldn't this at least be documented?

Please add query string support

Is it possible to add support for query string?

I read the current docs on GitHub and it is nice to have segment, multiple segment, route model binding, and customizing the model key. I might have miss it but I can't find how to use query string on Laravel Folio. Somehow I need it on most of my project and I fall in love with this Laravel Folio.

Missing URI prefix when calling `php artisan folio:list`

Folio Version

1.1.4

Laravel Version

10.32.1

PHP Version

8.2.4

Description

When I run php artisan folio:list, the returned path is missing the URI-prefix when specified.

I get this:
GET /test ......

I expect the result to be this:
GET /foo/test ......

Steps To Reproduce

Put this method in your FolioServiceProvider:

   /**
     * Bootstrap services.
     */
    public function boot(): void
    {
        Folio::path(resource_path('foobar'))->middleware([
            '*' => [
                //
            ],
        ])->uri('foo/');
    }

run php artisan folio:list

Route Model Bidding + Route Multi-Segments

Folio Version

1.0.0

Laravel Version

Latest

PHP Version

8.1.21

Description

What

I don't know if an update to README.md (docs) is enough or if the Laravel team wants to do something about it, but the multi-parameter route system eliminates Route Model Bidding:

Something like this:

CleanShot 2023-07-26 at 3 03 24

When accessing profiles/1 in the browser, [...ids].blade.php have priority over [User].blade.php, even [User].blade.php was created after. Perhaps the Laravel team knows about this and is aware, but here's my suggestion ๐Ÿ‘‡

Suggestion

Adapting make:folio:

The make:folio command can intercept this situation and give a visual feedback to the dev.

Throw An Exception

The access of a route that contains a trying to use Route Model Bidding together of Route Multi-Segments can simple try and exception providing a feedback to the dev.


Hope this help,

Thanks.

Steps To Reproduce

  1. Prepare your application, including seeding the database with fake users
  2. Install Folio and prepare them to be used
  3. Run make:folio "profiles/[...ids]"
  4. Run make:folio "profiles/[User]"
  5. Try to access the profiles/1 and check that [...ids] will works instead of [User]

Create paths automatically when not exists

I'd just finish installation of the Folio package to try it out on an existing project. After do some configurations I get this error:
Screenshot 2023-09-02 at 13 15 07

My suggestion is to create the path instead of throws an error

public function registerRoute(string $path, string $uri, array $middleware, ?string $domain): void
    {
        $absolutePath = $path;
        $path = realpath($absolutePath);
        $uri = '/'.ltrim($uri, '/');


        if (! is_dir($path)) {
            mkdir($absolutePath, 0777, true);
        }

        $this->mountPaths[] = $mountPath = new MountPath(
            $path,
            $uri,
            $middleware,
            $domain,
        );

        Route::fallback($this->handler())->name('laravel-folio');
    }

The shared variable in the `render` function can not be accessed between `@php` and `@endphp` directives

Folio Version

1.1.0

Laravel Version

^10.10

PHP Version

^8.1

Description

I can not access the shared variable inside the new render function between @php and @endphp directives. Let me demonstrate with the next two examples of code

// The code example that @nunomaduro uses 

<?php
    use function \Laravel\Folio\render;

    render( function($view) {
        $post = ['title' => 'Welcome Render Method!'];

        return $view->with('post', $post);
    });
?>

 // The value of `title` is printed out successfully
<?php echo $post['title']; ?>

But when I use the previous code between @php and @endphp directives the Undefined variable $post error is triggered

@php
    use function \Laravel\Folio\renderWhen;

    renderWhen(true, function($view) {
        $post = ['title' => 'Welcome Render Method!'];

        return $view->with('post', $post);
    });
@endphp

@dd($post);

Steps To Reproduce

NULL

Route model binding connection

Folio Version

1.1.3

Laravel Version

10.22.0

PHP Version

8.2.3

Description

It seems like the Folio route model binding resolution happens before middlewares are applied ๐Ÿค”. Thus, in my case, I had a middleware in charge of changing the current database connection dynamically.

I tried using the default routing system in the same project and things started working as expected. Back to Folio, it's no longer working (resolving the suitable database connection).

Steps To Reproduce

Using Folio, create a middleware that sets the default database connection. Route model binding will still use the default.

Add option to change path of "view/pages"

kindly use a Service class in Config which will return a string value from .env file for getting default path which is "views/pages".

so from .env file a developer can change default directory. and that class can be replaced by new call in case of complex directory structure like modules, multitenancy, etc.

Terminable middleware not executed

Folio Version

v1.0.0-beta.2

Laravel Version

v10.17.1

PHP Version

8.2.8

Description

When registering terminable middleware in the FolioServiceProvider, the terminate() function of the middleware isn't executed.

Steps To Reproduce

  1. Create a terminable middleware class
  2. Add a log statement to the middleware's terminate() method: info('terminating')
  3. Register the middleware in the FolioServiceProvider:
    Folio::route(resource_path('views/pages'), middleware: [
        '*' => [
            TheTerminableMiddleware::class,
        ],
    ]);
  4. Load a folio page
  5. Check the logs
  6. Find no terminating log entry

Can't generate url route which starts with "/index"

Folio Version

1.1.5

Laravel Version

10.43

PHP Version

8.2

Description

Hello,
Thanks for the great job. Laravel Folio is really cool thing.

I have some categories and pages on my website, which have url path like:
domain.com/carrier/indexed/safe-return OR domain.com/carrier/fixed/index-protector-7

So the problem is that Folio is replacing all "/index" and "/index/" strings in the whole url if route() function was used to generate url. And result will be:
domain.com/carrier/ed/safe-return OR domain.com/carrier/fixed-protector-7

As you may understand, all "/index" were removed from URL, so I can't generate url correctly using route() function. If copy/paste full url to browser or generate it in another way, it works.

I found it's happening in FolioRoutes.php class.

image

Any chance it can be fixed somehow? Got a lot of pages with a slugs like "some-page/index-some-name".

Steps To Reproduce

Create strtucture like:

image

Try to generate url using route() function.

Url for /indexed/ folder will not be generated correctly.

Second problem, create any model and give slug like "index-protector-7" and try to make a url like domain.com/index-protector-7 using route() function. Part "/index" will be removed from url.

image

Feature Idea - Add Function for Metadata

Feature Request Idea

I think it would be great if we could add metadata to a folio page. I am thinking of how it works in Nuxt with Nuxt Content if your familiar (https://content.nuxtjs.org/guide/writing/markdown).

In Nuxt your content directory (similar concept to the resources/views/pages/*) which may look like

---
type: 'blog'
title: 'Title of the page'
description: 'meta description of the page'
---

<!-- Content of the page -->

A purpose for these front-matter metadata is to be able to query the pages and display them in a list. For example, if you have a blog you may want to display a list of all the blog posts that based on some criteria.

an implementation of this could be something like

collect(Folio::pages())->where('type', 'blog')->sortBy('createdAt')->take(5);

More on the metadata part...idk exactly how it would work best, maybe something like:

<?php

use function Laravel\Folio\{metadata};

metadata([
    'type' => 'blog',
    'title' => 'Dashboard',
    'description' => 'meta description of the page',
]);

?>

<div>
    Blogs
</div>

Exceptions PossibleDirectoryTraversal in Windows system

Folio Version

1.0.0-beta.1

Laravel Version

10.16.1

PHP Version

8.1.10

Description

When trying on a Windows system, I found a problem with verifying that the blade file exists at Laravel\Folio\Pipeline\EnsureNoDirectoryTraversal class.

image

if (! Str::of(realpath($view->path))->startsWith($state->mountPath.'/')) {
    throw new PossibleDirectoryTraversal;
}

And I solved the problem through the use DIRECTORY_SEPARATOR to be

if (! Str::of(realpath($view->path))->startsWith($state->mountPath . DIRECTORY_SEPARATOR)) {
    throw new PossibleDirectoryTraversal;
}

Thanks,

Steps To Reproduce

  1. Install laravel/folio:^1.0@beta.
  2. Run php artisan folio:install.
  3. Create pages/schedule.blade.php file

Support non blade files

There appears to be an API exposed for using Folio with a custom response Folio::renderUsing. However, if I do something like the following to render components with Inertia, it only works when I have the same directory structure in the default views/pages folder.

Folio::renderUsing(function (Request $request, MatchedView $matchedView) {
    $path = Str::between($matchedView->relativePath(), '/', '.blade.php');
    return Inertia::render($path, $matchedView->data);
});
Folio::route(resource_path('views/pages'), middleware: [
    '*' => [
        //
    ],
]);

example directory structure that successfully renders svelte components using Inertia:

/
โ””โ”€โ”€ resources
    โ”œโ”€โ”€ views
    โ”‚   โ””โ”€โ”€ index.blade.php
    โ”‚       โ””โ”€โ”€ users
    โ”‚           โ”œโ”€โ”€ [User].blade.php
    โ”‚           โ””โ”€โ”€ index.blade.php
    โ””โ”€โ”€ js
        โ””โ”€โ”€ Pages
            โ””โ”€โ”€ index.svelte
                โ””โ”€โ”€ users
                    โ”œโ”€โ”€ [User].svelte
                    โ””โ”€โ”€ index.svelte

ideally we could modify the resource path and add a value in a config file or in the service provider to tell Folio to search for svelte files instead of blade files so we could have the following directory structure instead:

/
โ””โ”€โ”€ resources
    โ””โ”€โ”€ js
        โ””โ”€โ”€ Pages
            โ””โ”€โ”€ index.svelte
                โ””โ”€โ”€ users
                    โ”œโ”€โ”€ [User].svelte
                    โ””โ”€โ”€ index.svelte

The setup could look something like this:

Folio::extension('svelte');
Folio::renderUsing(function (Request $request, MatchedView $matchedView) {
    return Inertia::render($matchedView->relativePath(), $matchedView->data);
});
Folio::route(resource_path('js/Pages'), middleware: [
    '*' => [
        //
    ],
]);

`index` blade file with deeply nested model route binding not working

Folio Version

1.1.0

Laravel Version

10.10

PHP Version

8.2.8

Description

index blade file, with deeply nested routes with model binding not working as expectedis in a folder using the complete namespace (model location).

What's happening?

When trying to use route binding using multiple nested folders:

  • user/[.App.Models.User]/posts/[.App.Models.Post]/index.blade.php
    It returns 404 even if it exists.

Works as expected when using:

  • user/[User]/posts/[Post].blade.php
  • user/[.App.Models.User]/posts/[.App.Models.Post].blade.php

Working using:

image

Steps To Reproduce

Create a simple structure as:

image

Nested model route binding disables views

Folio Version

1.1.2

Laravel Version

10.26.2

PHP Version

8.2.3

Description

This issue is, I think, related to the issue #105 and was introduced in version 1.1.1

When using Folio I'm unable to display a create page when a subfolder [Model] exists.
The index page is however correctly displayed.

Steps To Reproduce

Here's what my pages folder look like:

Screenshot 2023-10-09 at 10 25 20

And here's what php artisan folio:list shows:

Screenshot 2023-10-09 at 10 43 56

  • The movies/index.blade.php correctly displays all of my movies
  • The movies/[Movie].blade.php correctly displays the details of a single movie (if i change it to movies/[Movie]/index.blade.php it also works)
  • The movies/[Movie]/characters.blade.php correctly displays all characters in a movie
  • The movies/create.blade.php doesn't work and returns a 404 error

If I remove the [Movie] folder the create page is displayed.
If I force composer to use v1.1.0 everything works as intended.

Allow modification of Route Methods

This is a placeholder for a PR that allows me (or end users) to solve this issue without Laravel maintaining anything.

Original tweet: https://twitter.com/snellingio/status/1688643282408964097

Pitch I made in the internals discord:

It would be cool to add a method to compile an anonymous class or function to handle post requests.

Currently: Laravel Volt allows us to very easily hook up forms with Folio page routing.

Imagine a contact-us form.

pages
โ””โ”€โ”€ contact-us.blade.php

The Volt component would look something like:

<?php

use function Livewire\Volt\{rules, state};

state(['issue_type' => '', 'message' => '', 'email' => '',);
rules([ 'issue_type' => ['bail', 'required'], 'message' => ['required'], 'email' => [ 'required', 'email', ],]);

$save = function () {
    // do the work
};
?> 

โ€ฆ
<form wire:submit="save">

This is amazing. However, there are a lot of times / projects that Iโ€™m not using Livewire.

Iโ€™d love if we had some sort of post or store helper inside folio directly.

<?php

use function Laravel\Folio\{post};

post(function(Request $request) {
    // do the work
});
?>

โ€ฆ
<form action="/contact-us" method="POST">

I think it would work the exact same, it just compiles to an anon function. The actual route would stay the same, and we could route based on the request type.

Folio should work with other template engines (like Twig)

Hey,

we set up our first folio project und we prefer using twig (via twigbridge) over blade templates.

Folio don't finds templates with .twig extension. After digging the code a little, i found many hardcoded ".blade.php" refreences.

Wouldn't it be nice if the template extension is configurable via config?

Thanks in advance!

Add support for dynamic route name

I'm trying to localize my app with Folio without creating duplicated lang directories inside /pages

So far I came up with this, but the problem is that localized Folio routes are being overwritten by each others and using the route() helper leads to the same url. Is there a way to suffix route names with dynamic value, in my case would be the current locale?

Folio::path(resource_path('views/pages'))
    ->uri('en')
    ->middleware([
        '*' => ['lang:en'],
    ]);

Folio::path(resource_path('views/pages'))
    ->uri('fr')
    ->middleware([
        '*' => ['lang:fr'],
    ]);

lang middleware

public function handle(Request $request, Closure $next, string $lang): Response
{
    // Set application locale
    app()->setLocale($lang);

    // Remember the last known locale for automatic redirects
    if ($request->cookie('last_known_locale', null) !== $lang) {
        cookie()->queue('last_known_locale', $lang, 60 * 24 * 365);
    }

    return $next($request);
}

routes/web.php

Route::get('{path}', function (Request $request) {
    $lang = $request->cookie('last_known_locale', null);

    $lang ??= config('app.fallback_locale');

    return redirect()->to($lang.'/'.$request->path());
})
    ->where('path', '^(?!(en|fr)).*');

index.blade.php

<?php

use function Laravel\Folio\name;

name('home');
?>

php artisan folio:list

GET       /en ....... home โ€บ resources/views/pages/index.blade.php
GET       /fr ....... home โ€บ resources/views/pages/index.blade.php

Default route name

Instead of manually go to each view and set the route name Laravel\Folio\name('website.register'), wouldn't be nice to set default route name for each view/page dynamically?

For example pages/login.blade.php => route('login') and pages/users/profile => route('users.profile')

Aaand to be greedy would add As() option to the Folio::path(..)->as('website.'), so all routes now inside this path would have its route name as route('website.login') and ('website.users.profile')

This is just a feature idea I thought about the other day, Thanks ๐Ÿ’Œ

Route::has doesn't pick up folio pages

Folio Version

1

Laravel Version

10

PHP Version

8

Description

Route::has doesn't seem to pick up folio pages.

Example, in my navbar:

@if(Route::has('login'))
    <a href="{{ route('login') }}">
        {{ __('Login') }}
    </a>
@endif

In my login.blade.php page:

use function Laravel\Folio\name;

name('login');

My link for the login page doesn't show up in the navbar.

Steps To Reproduce

Create a view that uses Route::has to check if a named folio page exists. Seems to always be false.

Could folio have a 'cut down' version of laravel

So from a brand new installation of Laravel I just added folio and vapor-core and had a site up in "no time".

That got me wondering - if I had a simple content site - like documentation of a product say, could all the "other stuff" like models, controllers be removed from the base framework? Does this impact the size of the lambda function?

I see there is scope for models so this is only for the simple site use case.

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.