Giter Site home page Giter Site logo

permalink's People

Contributors

crnkovic avatar israelortuno 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

Watchers

 avatar  avatar  avatar  avatar  avatar

permalink's Issues

Performance

Hi

I'm re-writing an old CMS based site in laravel, and I need to preserve existing hierarchical url structure.
What I have is basically a nested set cateogory tree with products.
simple examples:
/category/sub-cat/product-name
/othercat/some-subcat/3rd-level-sub-cat/another-product

I need to keep the hierarchy in the urls, and keep them clean.

I came across your package and have spent some time getting it integrated. I was initially pleased because I can duplicate the URL structure exactly, and routing seems to work consistently.

However I've hit a problem with performance.
I now have about 50 categories and 500 products in the permalinks table for testing.
At this point a simple page takes about 0.85 secs to output, and a couple simple timers show that around 0.65 of that is taken in Router->load() function.
route:list goes from 0.12sec without permalinks on to 0.58 with it.
(fyi hardware is substantial dedicated dev server in the office)

This is in early dev and I dont have route caching turned on, but at the moment I have closures in route files so thats out, or requires rethink of other routing.
But in anycase I will have 10,000+ plus items to route. That would be outside my laravel experience so I ask question: Is it realistic to load that many routes into route cache anyway?

There's a lot of heavy duty stuff in the load() function: load whole table, set up tree, insert routes etc.
Isnt iit possible to just do a lookup of url in a middleware? maybe even save complete path to permalinks table?

Anyway I'd appreciate your thoughts on this.

Regards

l.

Supported Naming Conventions for SEO Field

What are the supported input naming conventions for auto updating the SEO field json objects? I was able to find a few of them in the undocumented permalink_forms repo i.e. permalink[seo][advanced][robots][index]. But wasn't sure if there are others, specifically for like opengraph and twitter tags.

Feature Idea - Permalink specific route name aliases

What would you think about the ability to add a route name alias to an individual record without requiring an explicit declaration of the entity Id? This would be useful in development workflows where the database entries aren't always going to be in sync from environment to environment.
For example, I encountered an issue where I was using the permalink route name to reference a specific page (i.e. route(permalink.42)) on a local environment. This creates an issue if that id value doesn't exist in the other environment databases. Even if we created a seed file for modifications made to the permalinks table to ensure it's kept up to date across all env's, the issue then would be potential conflicts with the changes made to the table's current index (id in this case). Not to mention, generally speaking that would just add another step to the development workflow.

I initially considered three workarounds to deal with the issue currently:

  1. explicitly reference the slug with: url('my-permalink-parent', 'my-permalink-child') in the view;
  2. Query the page object by slug within the controller and then passing the object as variable to the view where i could use the default $page->route method.
  3. Use an alias/action map.

The first two workarounds were not really ideal as they used the hard-coded page slugs as primary point of reference - which means if the slug changes, we'd return an error. If we needed to modify the reference in any way, it would require us to go back and modify the code which isn't very scalable and gets cumbersome when dealing with constantly having to go through build & deployment pipelines, etc.
The third workaround would require a unique action for the referenced entry, which i think defeats the purpose of the dynamic nature of the package.

So i was thinking it might smooth things out if we could assign a route name to an individual record, so in these instances we could just use something like: route('permalink.my_permalink_child'). Then we'd only have to make sure that route name exists in the Permalink table for it's respective entry, regardless of what that entry's id value happens to be.

Maybe it can be included in the "custom name column" idea mentioned in #5
What do you think?

Existing Route Name Question

Pretty interesting package you've put together. I'm considering implementing it. I had a question regarding how the package treats existing named routes?

Nesting of models

Hi,

I was thinking if it would make sense to introduce model nesting a bit differently.
As far as I understand it is possible to mimic the default Laravel behavior like assigning one model as the unique parent e.g. /jobs/frontend-web-developer.

How would I go about a scenario where a model can be parent to multiple other models and vice versa?

I would like to nest a page model something like this:

-Page 1 {page-1}
--Page 2 {page-1/page-2}
----Page A {page-1/page-2/page-a}
--Page 3 {page-1/page-3}
-Category A {category-a}
--Page 4 {category-a/page-4}
----Page 5 {category-5/page-4/page-5}
--Page 6 {category-a/page-6}
-Page 7 {page-7}
--Category A {page-7/category-a}

One issue is the restriction that parent_for must be unique. I was thinking with a pivot table using parent id, child id and entity type this could be solved?

Having the model id, entity type and all it's children the slugs still could be recursively updated I think.

Any thoughts on that or a better way to achieve that sort of nesting?

*Something else: what is the reason you check $permalink->getOriginal('slug') !== $permalink->slug?

/**
     * Updating event.
     *
     * @param $model
     */
    public function updating($permalink)
    {
        if ($permalink->getOriginal('slug') !== $permalink->slug) {
            $this->ensureSlugIsUnique($permalink);

            config('permalink.rebuild_children_on_update')
                ? $this->path->recursive($permalink)
                : $this->path->single($permalink);
        }
    }

Question - Output SEO values in view

Is there a built in helper method to display the SEO data in a view? For example, the arcane package uses the seo_helper()->render() method. Is there anything like that in this package? Or do I have to write my own methods to display the seo data?

Default parent_id on models

Hi,

great package! Was looking for a while for something like this and stumbled about your package in this Medium article.

I have a model Pages and one Category, each Page belongs to one Category and Categories can have many Pages.

I have a factory to seed Pages like this:

$factory->define(Page::class, function (Faker $faker) {

    $title = $faker->sentence(rand(3, 7));
    $category = Category::all()->random();

    return [
        'title' => substr($title, 0, strlen($title) - 1),
        'category_id' => $category->id,
        'permalink' => [
            'parent_id' => $category->permalink->permalinkable_id,
        ],
    ];
});

This works all fine but I'm wondering how to tell my Page model to always use the category it belongs to as parent_id?

Error with loading permalink action

Laravel: 5.5 (tested 5.6 with same results)

I'm trying to set this up so i can use the action loaded from the db to dynamically display different view templates based on the pages permalink type. (I'm setting nested routes to show state/city index pages, with a parent->child relationship). Hoping you can give me some insight on the error i'm running into?

Getting a class does not exist error when navigating to permalink routes if an action is set for the record in the database. Using the permalinks work fine otherwise, when no action is set in the db .

Class PageController does not exist

The class definitely exists, as the default method defined in the model is in the same controller class.

ReflectionException thrown with message "Class PageController does not exist"

Stacktrace:
#39 ReflectionException in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Container\Container.php:752
#38 ReflectionClass:__construct in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Container\Container.php:752
#37 Illuminate\Container\Container:build in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Container\Container.php:631
#36 Illuminate\Container\Container:resolve in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Container\Container.php:586
#35 Illuminate\Container\Container:make in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:732
#34 Illuminate\Foundation\Application:make in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Route.php:226
#33 Illuminate\Routing\Route:getController in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Route.php:796
#32 Illuminate\Routing\Route:controllerMiddleware in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Route.php:757
#31 Illuminate\Routing\Route:gatherMiddleware in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Router.php:671
#30 Illuminate\Routing\Router:gatherRouteMiddleware in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Router.php:651
#29 Illuminate\Routing\Router:runRouteWithinStack in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Router.php:635
#28 Illuminate\Routing\Router:runRoute in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Router.php:601
#27 Illuminate\Routing\Router:dispatchToRoute in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Router.php:590
#26 Illuminate\Routing\Router:dispatch in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:176
#25 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30
#24 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\yajra\laravel-disqus\src\DisqusMiddleware.php:19
#23 Yajra\Disqus\DisqusMiddleware:handle in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149
#22 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#21 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\barryvdh\laravel-debugbar\src\Middleware\InjectDebugbar.php:58
#20 Barryvdh\Debugbar\Middleware\InjectDebugbar:handle in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149
#19 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#18 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\fideloper\proxy\src\TrustProxies.php:56
#17 Fideloper\Proxy\TrustProxies:handle in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149
#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#15 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:30
#14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149
#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#12 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:30
#11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149
#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#9 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php:27
#8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149
#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#6 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\app\Http\Middleware\CheckForMaintenanceMode.php:34
#5 App\Http\Middleware\CheckForMaintenanceMode:handle in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149
#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#3 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:102
#2 Illuminate\Pipeline\Pipeline:then in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:151
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:116
#0 Illuminate\Foundation\Http\Kernel:handle in E:\Backup\wp-dev\htdocs\laravel\vacationrentals\public\index.php:54

Here's the method being called from the db:

	/**
	 * @return \App\Models\Page
	 */
	public function showStatePage(){
		return view('pages.state');
	}

And my page model:

class Page extends Model implements Permalinkable
{
	use HasPermalinks;
	use Translatable;
	/**
	 * The database table used by the model.
	 *
	 * @var string
	 */
	protected $table = 'pages';
	protected $guarded =  [];
	public $translatedAttributes = ['name', 'content'];

	//Enable permalink & seo management
	public $managePermalinks = true;

	/**
	 * Page Category relationship
	 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
	 */
	public function category()
	{
		return $this->belongsTo( 'App\Models\PageCategory', 'category_id', 'id');
	}

	/**
	 * Get the model action.
	 *
	 * @return string
	 */
	public function permalinkAction()
	{
		return PageController::class . '@showStaticPage';
	}

	/**
	 * Get the options for the sluggable package.
	 *
	 * @return array
	 */
	public function slugSource(): array
	{
		return ['source' => 'permalinkable.name'];
	}
}

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.