RomainB

RomainB

Member Since 2 Weeks Ago

Toulon

Experience Points 3,790
Experience Level 1

1,210 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 32
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

19 Aug
23 hours ago

RomainB started a new conversation What Is The Best Way To Manage An Unregistered Visitor Rating System? Token? IP?

Hi all, I want my website visitor to be able to tell me by two simple button if some post are 'Usefull' or 'Useless', like thumbs.

I know some packages could do this with some lines of code but I also want with this system to learn some relationship tricks.

Only my post will be "rateable", so I think I don't need a polymorphic structure.

What I have in mind:

Rate table with: a token cookie or an IP, or twice?? post_id rate (boolean: 1 = usefull, 0 = useless)

Rate model belongsTo Post Post model hasMany Rate

My question is: what is the best way to store "unique" visitor in my table? a token? the IP address of visitor? twice? something else? Maybe Laravel includes some magic tricks to catch "unique visitor which have already rate post"?

I welcome any advice which could help me.

Thanks.

17 Aug
2 days ago

RomainB left a reply on Access Form Request From Observer

To cleanup your code, you can also clarify your Customer bank, document, company and relationship creation. And even the update: Laravel "auto-retrieve" from request the data if your inputs name is the same as you database field.

For example, this update will work:

Customer::where('user_id', Auth::user()->id)
            ->update([
                'title',
                'middlename' =>  isset($request->middlename) ? $request->middlename : "",
                'phone',
                'gender',
                'DOB',
                'marital',
                'residential_address',
                'city',
                'state',
                'lga',
                'nationality',
                'complete_registration' => 1 ]);

In my project I also included a "with_user_id" helper declared in "app\helpers.php":

    function with_user_id($array)
    {
        return Arr::add($array, 'user_id', Auth::id());
    }

which I use like this:

$post = Post::create(with_user_id($request->only(
      'user_id',
      'category_id',
      'comment_authorized',
      'header_image_url',
      'title_fr',
      'title_en',
      'header_image_title_fr',
      'header_image_title_en',
      'header_image_alt_fr',
      'header_image_alt_en',
      'seo_title_fr',
      'seo_title_en',
      'seo_slug_fr',
      'seo_slug_en',
      'seo_description_fr',
      'seo_description_en',
      'content_fr',
      'content_en'
)));

RomainB left a reply on Build Wordpress Like CMS

I use Tinymce, which is pretty simple to manage into Laravel project: https://medium.com/@bvipul/integrate-tinymce-editor-in-your-laravel-installation-with-a-filemanager-235894910531

The text editor modify the textarea to insert bbcode/html button and even image uploader. Then you just have to parse the database output

16 Aug
3 days ago

RomainB left a reply on [email protected] With A Call To $this->anotherAction() Isn't Working?

Woaw. It's just... The shame...

Is that possible to delete this post? Lol

RomainB started a new conversation [email protected] With A Call To $this->anotherAction() Isn't Working?

Hi. To manage post on a blog website, I've got a high-level category named "Blog" displayed on /blog/, and some others categories displayed on root directory with the uri /category/{category}.

To display category's post I've got a CategoryController with show() method:

    public function show(Category $category)
    {
        $posts = $category->posts;
        return view('public.post.index')
                ->with('posts', $posts);
    }

And to display "blog" post, I've got a blog() method, which to DRY my code, call $this->show() method:


    public function blog()
    {
        $category = Category::findOrFail(1);
        $this->show($category);
    }

I've got the routes: /category/{category} to display all categories's post, and /blog/ to filter only the post where category_id = 1

Don't know if it's the better way to do this (I could probably simply filter /blog/ uri in my show() method) but this isn't the question.

In fact I'M just surprised to see that $this->show($category) in my blog() method, works (tested with dd()) but the return view isn't! Only a white page is rendered when /blog is requested

My posts table for now just have 4 rows, all for /blog/ so the root uri: /category/1 and /blog should be the same.

I tried to dd($posts) > in the show() method > The 4 rows are properly return in both ways (/blog and /category/1). So why the view() method silently screw up on /blog request?

10 Aug
1 week ago

RomainB left a reply on How To Properly Install Package?

@eslamahmed Thanks for the link, but my choice is made for ContentTools. Even if it's not the simplier to install.

My question concerns also future libraries that I may want to include in my projects. What the proper way to install package?

RomainB started a new conversation How To Properly Install Package?

Hi all, I want to install the WYSIWYG editor ContentTools on my Laravel project.

But I'm not very sure how to do it and I'm afraid to pollute my project's folder with useless files.

I search over the web. It seems I need to install NodeJS then npm, then grunt, then git, then.... woaw????!!!

Does them all are necessary to just install a text editor?

What's the correct procedure to install this type on library on my project?

Thanks for advice.

RomainB commented on Simpler Debugging With Laravel Telescope

I had exactly the same problem, using Xampp on windows: Telescope wasn't working at all: I was able to load Telescope with the normal path: localhost/myproject/public/telescope

But I observe that every links in the menu was wrong: localhost/telescope/queries, localhost/telescope/requests, etc...

So I guessed that path crashed all telescope. I tried to modify the .env file to set the TELESCOPE_PATH, but all my attempts were futile: telescope home page became localhost/myproject/public/myproject/public/telescope, other link was corrects but telescope wasn't watching at all.

I saw in this tutorial that Jeffrey was using Virtual Hosts, so I tried this out and configure my Xampp server to listen on "myproject.local". And it worked!

Telescope is now fully working on myproject.local/telescope and all links are corrects!

To set virtual hosts on Xampp server on Windows 10, go at: https://www.cloudways.com/blog/configure-virtual-host-on-windows-10-for-wordpress/

The tutorial was made for Wordpress but it work for all installations.

09 Aug
1 week ago

RomainB left a reply on ReflectionException (-1) Class Post Does Not Exist

Damn!!!! I got it!!!!

Entirely my fault. In web.php i binded the Post model:

// route–model binding
Route::model('post', 'Post');

I don't even know why!

Thanks you all for your time.

RomainB left a reply on ReflectionException (-1) Class Post Does Not Exist

Thanks for help, but again the problem is not here :cry:

I tried with a fresh model and exception occurs:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
}

And i don't think namespace is required, my Category model works properly:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $guarded = [];

    public function children()
    {
        return $this->hasMany('Category', 'parent_id');
    }
    
    public function parent()
    {
        return $this->belongsTo('Category', 'parent_id');
    }
    
    public function posts()
    {
        return $this->hasMany('Post');
    }
}

RomainB left a reply on ReflectionException (-1) Class Post Does Not Exist

@munazzil Thanks for the compact function but it doesn't help. Problem occurs also in destroy function which can't be more simplier:

    public function destroy(Post $post)
    {
        $post->delete();
        return redirect()->route('admin::post.index');
    }

I also clean all my controller, error occurs with this:

<?php

namespace App\Http\Controllers\AdminZone;

use App\Post;
use App\Category;
use Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\PostStoreUpdateRequest;

class PostController extends Controller
{
}

It isn't a syntax error... Problem occurs when Laravel need to load a post at HTTP request's moment: destroy, edit and probably update (can't submit edit's form for now...)

RomainB left a reply on How To Dry Up This Part Of My Code?

@erikverbeek > Woops. Miss that part.

@clevonnoel > Agree with you but everybody makes with his capabilities.

@nabilunfarhanun > What I would do in this case. Filter "accepted forms" with a simple class .thisFormCanCallAjax on forms, and errors in class instead of unique id. And then just retrieve the ID of form which is submitted with form.attr('id')

$("form.thisFormCanCallAjax ").submit(function(e) {
    e.preventDefault();
    var form = $(this);
    var formId = form.attr('id');
    var url = form.attr('action');
    $.ajax({
        type: "POST",
        url: url,
        data: $(formId).serialize(),
        success: function(data)
        {
            if(data=="success")
            {
                location.reload();
            }
            else
            {
                var html = "<ul>";
                for(var dat in data)
                {
                    for (var x in data[dat])
                    {
                        html = html+"<li>"+data[dat][x]+"</li>";
                    }
                }
                html = html+"</ul>";
                $(formId +" .errors").attr("class","alert alert-danger");
                $(formId +" .errors").html(html);
            }
        }
    });
});

RomainB left a reply on ReflectionException (-1) Class Post Does Not Exist

Maybe you made a great long shot. Take a look:

Psy Shell v0.9.9 (PHP 7.3.7 — cli) by Justin Hileman

>>> $category = new Category
[!] Aliasing 'Category' to 'App\Category' for this Tinker session.
=> App\Category {#3014}

>>> $post = new Post
[!] Aliasing 'Post' to 'App\Http\Resources\Post' for this Tinker session.
TypeError: Too few arguments to function Illuminate/Http/Resources/Json/JsonResource::__construct(), 0 passed in Psy Shell code on line 1 and exactly 1 expected

>>> $post = new App\Post
=> App\Post {#3023}

>>> resolve(App\Post::class);
=> App\Post {#3008}

use App\Post solved the problem in tinker:

>>> use App\Post;
>>> Post::first()
=> App\Post {#3028
     id: 1,
     user_id: 1,
     category_id: 5,
     created_at: "2019-08-07 15:53:32",
     updated_at: "2019-08-07 15:53:32",
     displayed_at: null,
     comment_authorized: 1,
     title: "azeazeazezaeazeazeazeazeazeaezae",
     content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eu eros accumsan, vestibulum turpis et, eleifend dolor. Nam sed consequat nunc. In non dolor at diam venenatis mattis ut ac sapien. Integer et imperdiet neque, vitae fringilla mi. Quisque fringilla, massa eget vestibulum volutpat, mi odio ultrices nisl, sit amet sodales felis eros at elit. Aenean mattis tortor scelerisque iaculis viverra. Phasellus tincidunt tellus et dolor dictum, et vulputate urna efficitur. Phasellus quis risus et libero pellentesque venenatis eget vel est. Etiam ornare venenatis odio, ut tempus nisi aliquam malesuada. Fusce ultrices vulputate lorem, vel porttitor eros. In tortor lorem, auctor et augue finibus, mollis blandit enim. Nam nec massa lorem. Integer pulvinar consequat odio viverra maximus. Suspendisse potenti. Aenean ut condimentum magna.",
   }

But the problem isn't the service provider because I don't even know what this file is used for, so I never opened it:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}

My post resource file is also clean as it was at his creation (looked at it when tinker said "Too few arguments [...] JsonResource::__construct()[...]:

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class Post extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return parent::toArray($request);
    }
}

I also tried another dump-autoload:

C:\xampp\htdocs\qaa>composer dump-autoload
Generating optimized autoload files> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: barryvdh/laravel-debugbar
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: fideloper/proxy
Discovered Package: kris/laravel-form-builder
Discovered Package: laravel/tinker
Discovered Package: laravelcollective/html
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
Generated optimized autoload files containing 3782 classes

C:\xampp\htdocs\qaa>php artisan config:clear
Configuration cache cleared!

C:\xampp\htdocs\qaa>php artisan tinker
Psy Shell v0.9.9 (PHP 7.3.7 — cli) by Justin Hileman
>>> $post = new Post
[!] Aliasing 'Post' to 'App\Http\Resources\Post' for this Tinker session.
TypeError: Too few arguments to function Illuminate/Http/Resources/Json/JsonResource::__construct(), 0 passed in Psy Shell code on line 1 and exactly 1 expected
>>> $post = new App\Post
=> App\Post {#3016}
>>> $category = new Category
[!] Aliasing 'Category' to 'App\Category' for this Tinker session.
=> App\Category {#3008}

RomainB left a reply on How To Dry Up This Part Of My Code?

Well.

As I see all your code is exactly the same except the ID in your html page.

Just set the same ID #myForm instead of #createForm and #updateForm and #errors instead of #createErrors and #updateErrors and you can call the same Ajax function with two forms.

Then you can create a submit-form.js and include it in your two html pages.

<script type="text/javascript">
    $("#myForm").submit(function(e) {
        e.preventDefault();
        var form = $(this);
        var url = form.attr('action');
        $.ajax({
            type: "POST",
            url: url,
            data: $('#myForm').serialize(),
            success: function(data)
            {
                if(data=="success")
                {
                    location.reload();
                }
                else
                {
                    var html = "<ul>";
                    for(var dat in data)
                    {
                        for (var x in data[dat])
                        {
                            html = html+"<li>"+data[dat][x]+"</li>";
                        }
                    }
                    html = html+"</ul>";
                    $("#errors").attr("class","alert alert-danger");
                    $("#errors").html(html);
                }
            }
        });
    });
</script>
08 Aug
1 week ago

RomainB left a reply on ReflectionException (-1) Class Post Does Not Exist

@eslamahmed > Already tried, and once again right now: no effect.

@talinon > I will have got a PostController outside of "AdminZone" which will uses only index and show method to display the blog posts. But, it's in a different namespace and for now, I don't have created it yet. The long shot was a good shot but not for now... For now, only routes is declared:

|        | GET|HEAD  | admin/post                     | admin::post.index       | App\Http\Controllers\AdminZone\[email protected]           | web,auth                                             |
|        | POST      | admin/post                     | admin::post.store       | App\Http\Controllers\AdminZone\[email protected]           | web,auth                                             |
|        | GET|HEAD  | admin/post/create              | admin::post.create      | App\Http\Controllers\AdminZone\[email protected]          | web,auth                                             |
|        | GET|HEAD  | admin/post/{post}              | admin::post.show        | App\Http\Controllers\AdminZone\[email protected]            | web,auth                                             |
|        | PUT|PATCH | admin/post/{post}              | admin::post.update      | App\Http\Controllers\AdminZone\[email protected]          | web,auth                                             |
|        | DELETE    | admin/post/{post}              | admin::post.destroy     | App\Http\Controllers\AdminZone\[email protected]         | web,auth                                             |
|        | GET|HEAD  | admin/post/{post}/edit         | admin::post.edit        | App\Http\Controllers\AdminZone\[email protected]            | web,auth                                             |
|        | GET|HEAD  | post                           | post.index              | App\Http\Controllers\[email protected]                     | web                                                  |
|        | GET|HEAD  | post/{post}                    | post.show               | App\Http\Controllers\[email protected]                      | web

This is my entire stacktrace, hope this is what you're expecting for (new into Laravel):


58
ReflectionException 
…\vendor\laravel\framework\src\Illuminate\Container\Container.php790
57
ReflectionClass __construct
…\vendor\laravel\framework\src\Illuminate\Container\Container.php790
56
Illuminate\Container\Container build
…\vendor\laravel\framework\src\Illuminate\Container\Container.php667
55
Illuminate\Container\Container resolve
…\vendor\laravel\framework\src\Illuminate\Container\Container.php615
54
Illuminate\Container\Container make
…\vendor\laravel\framework\src\Illuminate\Foundation\Application.php767
53
Illuminate\Foundation\Application make
…\vendor\laravel\framework\src\Illuminate\Routing\RouteBinding.php66
52
Illuminate\Routing\RouteBinding Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Router.php802
51
 call_user_func
…\vendor\laravel\framework\src\Illuminate\Routing\Router.php802
50
Illuminate\Routing\Router performBinding
…\vendor\laravel\framework\src\Illuminate\Routing\Router.php770
49
Illuminate\Routing\Router substituteBindings
…\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php37
48
Illuminate\Routing\Middleware\SubstituteBindings handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
47
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
46
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Auth\Middleware\Authenticate.php43
45
Illuminate\Auth\Middleware\Authenticate handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
44
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
43
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php75
42
Illuminate\Foundation\Http\Middleware\VerifyCsrfToken handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
41
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
40
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php49
39
Illuminate\View\Middleware\ShareErrorsFromSession handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
38
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
37
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php56
36
Illuminate\Session\Middleware\StartSession handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
35
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
34
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php37
33
Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
32
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
31
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php66
30
Illuminate\Cookie\Middleware\EncryptCookies handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
29
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
28
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php104
27
Illuminate\Pipeline\Pipeline then
…\vendor\laravel\framework\src\Illuminate\Routing\Router.php682
26
Illuminate\Routing\Router runRouteWithinStack
…\vendor\laravel\framework\src\Illuminate\Routing\Router.php657
25
Illuminate\Routing\Router runRoute
…\vendor\laravel\framework\src\Illuminate\Routing\Router.php623
24
Illuminate\Routing\Router dispatchToRoute
…\vendor\laravel\framework\src\Illuminate\Routing\Router.php612
23
Illuminate\Routing\Router dispatch
…\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php176
22
Illuminate\Foundation\Http\Kernel Illuminate\Foundation\Http\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php30
21
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\barryvdh\laravel-debugbar\src\Middleware\InjectDebugbar.php65
20
Barryvdh\Debugbar\Middleware\InjectDebugbar handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
19
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
18
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\fideloper\proxy\src\TrustProxies.php57
17
Fideloper\Proxy\TrustProxies handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
16
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
15
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php21
14
Illuminate\Foundation\Http\Middleware\TransformsRequest handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
13
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
12
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php21
11
Illuminate\Foundation\Http\Middleware\TransformsRequest handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
10
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
9
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php27
8
Illuminate\Foundation\Http\Middleware\ValidatePostSize handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
7
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
6
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php62
5
Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode handle
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php163
4
Illuminate\Pipeline\Pipeline Illuminate\Pipeline\{closure}
…\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php53
3
Illuminate\Routing\Pipeline Illuminate\Routing\{closure}
…\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php104
2
Illuminate\Pipeline\Pipeline then
…\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php151
1
Illuminate\Foundation\Http\Kernel sendRequestThroughRouter
…\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php116
0
Illuminate\Foundation\Http\Kernel handle
…\public\index.php55

RomainB left a reply on Prevent Multiple User Editing The Same Resource

Just a suggestion, maybe not what you want:

With a field "open_elsewhere" nullable-timestamp in table:

In [email protected] method

if open_elsewhere is not null and recently opened (manage this variable) > Sorry, you cannot edit this resource

else update line in table to set open_elsewhere at current_timestamp and return form view to edit

In [email protected] method:

update line in table with open_elsewhere to null

RomainB started a new conversation ReflectionException (-1) Class Post Does Not Exist

Hi. Got a headache...

I've just created all admin pages for "category" resource of a blog website. Everything is okay.

I tried to do exactly the same structure to manage "post" resource. [email protected], create and store is okay.

But now i'm trying to do the edit and i got a: ReflectionException (-1) Class Post does not exist The error occurs even on destroy function call.

I past few hours trying to search over the web (event in this forum), tried artisan config:cache, composer dumpautoload -o (also without -o ), verified my Post class doesn't have any syntax error, check composer.json autoload. Nothing worked! My composer.json:

    "autoload": {
        "psr-4": {
            "App\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },

My Post class:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $guarded = [];
    
    public function comments()
    {
        return $this->hasMany('Comment');
    }
    
    public function author()
    {
        return $this->belongsTo('User');
    }
    
    public function category()
    {
        return $this->belongsTo('Category');
    }
}

My PostController:

<?php

namespace App\Http\Controllers\AdminZone;

use App\Post;
use App\Category;
use Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\PostStoreUpdateRequest;

class PostController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }
    
    /**
     * Show the form for editing the specified resource.
     *
     * @param  Post  $post
     * @return \Illuminate\Http\Response
     */
    public function edit(Post $post)
    {
        $categories = Category::pluck('name', 'id');
        return view('admin.post.edit')->with('post', $post)->with('categories', $categories);
    }
// And some other code for other actions

My route:list for post:

GET|HEAD  | admin/post                     | admin::post.index       | App\Http\Controllers\AdminZone\[email protected]           | web,auth                                             |
|        | POST      | admin/post                     | admin::post.store       | App\Http\Controllers\AdminZone\[email protected]           | web,auth                                             |
|        | GET|HEAD  | admin/post/create              | admin::post.create      | App\Http\Controllers\AdminZone\[email protected]          | web,auth                                             |
|        | GET|HEAD  | admin/post/{post}              | admin::post.show        | App\Http\Controllers\AdminZone\[email protected]            | web,auth                                             |
|        | PUT|PATCH | admin/post/{post}              | admin::post.update      | App\Http\Controllers\AdminZone\[email protected]          | web,auth                                             |
|        | DELETE    | admin/post/{post}              | admin::post.destroy     | App\Http\Controllers\AdminZone\[email protected]         | web,auth                                             |
|        | GET|HEAD  | admin/post/{post}/edit         | admin::post.edit        | App\Http\Controllers\AdminZone\[email protected]            | web,auth                                             |

Does someone see anything wrong??

RomainB left a reply on How Can I Use Two Different Template For Same Route In Laravel

SEO bots aren't logged users.

They will only see the guest views.

RomainB left a reply on How Can I Use Two Different Template For Same Route In Laravel

https://laravel.com/docs/5.8/authentication#protecting-routes

You should use an auth middleware in your web.php, for example:

// public routes
Route::resource('post', 'PostController', array('only' => array('index', 'show')));

// Logged user only routes
Route::resource('post', 'PostController')->middleware('auth');
07 Aug
1 week ago

RomainB left a reply on Relation Between Same Users Table

https://laravel.com/docs/5.8/eloquent-relationships#one-to-many

In Laravel Documentation, it says:

Remember, Eloquent will automatically determine the proper foreign key column on the Comment model. By convention, Eloquent will take the "snake case" name of the owning model and suffix it with _id. So, for this example, Eloquent will assume the foreign key on the Comment model is post_id.

Like the hasOne method, you may also override the foreign and local keys by passing additional arguments to the hasMany method:

return $this->hasMany('App\Comment', 'foreign_key');

In your case it's the same table, so Laravel is searching a "user_id" inside the user table > There is not.

Add a coach_id column which you fill when a coach is selected(nullable if runner doesn't have one) and specify the coach user id inside of it. Then declare it in your belongsTo and hasMany methods:

class User extends Authenticatable
{
    public function coach() // Return Coach
    {
        return $this->belongsTo('App\User', 'coach_id');
    }

    public function runners() // Return User
    {
        return $this->hasMany('App\User', 'coach_id');
    }
}

RomainB left a reply on Store And Update Request Are The Same Except The Unique Id. A Way To Merge?

Well, I'm not very sure this is a good way to do. Assuming I add a segment /admin to my panel (which is the case): your conditions is always true.

So if I create my entire project with this rules and no /admin segment.

And then I say to myself "Hmmm, maybe I should add /admin segment" > All my /admin rules crash.

I think catching the HTTP method() is more sure.

RomainB left a reply on Store And Update Request Are The Same Except The Unique Id. A Way To Merge?

Your tip for sure is great when rules became more complicated, I'll probably use this way in future. In this case, they are very short and easily readable/supportable.

To check if I fully understand what you mean. You do something like that?

public function rules()
{
    if ($this->method() == 'PATCH') return $this->updateRules();
    else return $this->createRules();
}

protected function createRules() {
         return [
        'name' => 'required|string|max:50|unique:categories,name',
        'parent_id' => 'nullable'
    ];
}

protected function updateRules() {
         return [
        'name' => 'required|string|max:50|unique:categories,name,'.$this->category->id,
        'parent_id' => 'nullable'
    ];
}

RomainB started a new conversation Store And Update Request Are The Same Except The Unique Id. A Way To Merge?

Hi all, I'm creating my first full project(blog).

With the obsession to write DRY code, I created a CategoryStoreUpdateRequest (and not a StoreRequest + a UpdateRequest) to control the rules to pass and messages to return when store or update route is needed.

I'm using this personnal trick to do this:

public function rules()
    {
        $name_rules = ($this->method() == 'PATCH') // else == 'POST'
            ? 'required|string|max:50|unique:categories,name,'.$this->category->id
            : 'required|string|max:50|unique:categories,name';

        return [
            'name' => $name_rules,
            'parent_id' => 'nullable'
        ];
    }

I just want to know if some of you is seeing an issue to do this that way??

05 Aug
2 weeks ago

RomainB left a reply on Route('namedRoute') On $redirectTo Auth Module Isn't Working ??

Well, thanks! My log form redirects well now!

RomainB started a new conversation Route('namedRoute') On $redirectTo Auth Module Isn't Working ??

Hi all, I just want to automatically retrieve url of a named route to assign it on the $redirectTo variable of Auth module.

I'm using route() helper this way:

protected $redirectTo = route('admin::');

My route is declared in my web.php route file:

Route::get('/admin', '[email protected]')->name('admin::');

And route:list is correct:

GET|HEAD  | admin                          | admin::                 | App\Http\Controllers\[email protected]                | web,auth

But when I'm logging in, systems returns to me error: Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Constant expression contains invalid operations

I previously used direct declaration: $redirectTo = '/admin'; and everything was working fine but i prefer an automatic way, if the url is modified directly from the route file, so i don't have to modify all Auth file to modify $redirectTo.

What am I doing wrong??