Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Zachary Smith
    @zachisit
    or i just grab the user object and pass directly into the template
    then i can do the {% if user.HasCat %} logic directly in the template
    Zachary Smith
    @zachisit
    so according to this - https://stackoverflow.com/a/46608109/151438 - i can just type into the template itself Auth::user() and not need to grab/build object in Controller -> pass into template
    but if i wanted to determine and calculate special logic for a user prior to the View loading I guess I would do that in Controller and pass into the template

    i guess logic directly in my template like

    @if (Auth::user()->canFetch)
        hola
    @endif

    is probably just as well, instead of building the calculation in Controller and passing a bool into the template. but looking for smarter humans in the room to weigh in here

    Ben Johnson
    @cbj4074

    @zachisit Everything you're pondering above is more or less correct.

    What you want to avoid is cluttering your controller methods with logic. They should be very short-and-sweet. They are responsible for two things only: accepting inputs and returning outputs, and they should do that in as terse a way possible.

    Ben Johnson
    @cbj4074

    For example, when you say

    but if i wanted to determine and calculate special logic for a user prior to the View loading I guess I would do that in Controller and pass into the template

    a much better option might be Middleware, View Composers, Blade Service Injection, or a combination thereof.

    Zachary Smith
    @zachisit
    @cbj4074 resuming yesterday's conversation - working to declutter methods in my Controller and moving them outside - would those new class(es) holding these methods live in app/Http/Middleware or just on the app/ dir?
    Ben Johnson
    @cbj4074
    It doesn't really matter where you put them, at the end of the day. Laravel has default/preferred locations for some of them, like Middleware (as you noted), but you can organize however you like.
    xlcrr
    @xlcrr

    How can I get the max occurance of a value in a collection or from DB? Eg I have a column "affiliate" and I want to return the value that was featured the most times

    $contacts->max('affiliate'); is returning the string with the longest length :confused:

    do I have to count, groupBy, orderBy, and select the first result, or does laravel have some kind of ->most('value') feature?
    edvordo
    @edvordo
    I'm not aware of any such method. Then again, this is not entirely hard to build with eloquent
    Contact::distinct('affiliate')
      ->groupBy('affiliate')
      ->selectRaw('affiliate, count(*) as `count`')
      ->orderByDesc('count')
      ->first()
    xlcrr
    @xlcrr
    thanks, but I have to get a few values. It is possible to do that in 1 query ?
    I was hoping to get the collection, and perform the query on this, to avoid multiple calls
    edvordo
    @edvordo

    Well, you can also do something like this

    $contacts = Contact::all();
    
    $affiliates = $contacts->countBy('affiliate');
    $otherColumn = $contacts->countBy('other_column');

    yes, it's not in one query, actualy it pulls all results and then performs counts on that result, but ..

    xlcrr
    @xlcrr
    nice one! Thanks!
    $affilates->max(); returns the value, but how to get the key.. ?
    the max value is null :D
    xlcrr
    @xlcrr
    thanks for the help <3
    edvordo
    @edvordo
    You figured it out?
    Zachary Smith
    @zachisit
    hi all. how do i change the app's name i see in the browser tab. I see /config/app.php the "name" var. i changed that. ran php artisan config:cache and see same default "Laravel" returned
    Ben Johnson
    @cbj4074
    @zachisit I would expect that to do the job, but it's also possible that the view cache needs to be cleared. Try php artisan view:clear and see if it changes.
    Ulrich-Matthias Schäfer
    @Fuzzyma
    did you ever hit the case that a simple php dev server wont serve your index file?
    well it does for the root path but not for any directory
    ezekel
    @ezekel

    Hi guys can someone help me please, when the user login I will get his first group_id
    by using this boot method() in AppserviceProvider. So in this case the id is 5

     view()->composer('layouts.mainsidebar',function($view){
            $view->with('groupid', auth()->user()->getFirstGroup() );
     });

    Now my sidebarmenu is updating to /group/5 ,
    my problem is that when the user click the group menu example he click the "Serious group" and the page reload, so my new url will be like
    this http://mysite/group/10/dashboard. and I want my sidebar will be automatically updated too. I want my groupid be accessable to controller
    so that when I will add bonuses I know what groupid I'm going to use or insert to table.

    please help me thank you.

    my groups menu
    <a href="https://mysite/group/5">Fancy group</a>
    <a href="https://mysite/group/10">Serious group</a>
    <a href="https://mysite/group/30">Pretty girls group</a>

    sidebarmenu
    <a href="https://mysite/group/5/dashboard">Dashboard</a>
    <a href="https://mysite/group/5/bonuses">Bonuses</a>
    <a href="https://mysite/group/5/credits">Credits</a>

    I'm using Larvel 6.
    ezekel
    @ezekel
    I end up using Automatic Resolve Dependcies
    Am I right using this ?
    Ben Johnson
    @cbj4074
    @Fuzzyma Yeah, but there are just so many possible reasons for it... are you using Apache or NGINX? And are you referring to a index.html file or a index.php file?
    ezekel
    @ezekel

    I have this url I want to add active class to hreflink, but it's not working

    http://mysite/group/35/bonus

    class="nav-link {{ Request::is('bonus') || Request::is('bonus/*')? 'active' : '' }}

    Ben Johnson
    @cbj4074
    @ezekel Hmm, I don't think I've ever tried to use ternary syntax like that in a Blade template... do you get an error? Or the active class simply isn't applied?
    ezekel
    @ezekel
    @cbj4074 active class isn't applied, I got it working before when it's not nested
    Ben Johnson
    @cbj4074
    @ezekel What do you mean by "not nested"?
    ezekel
    @ezekel
    @cbj4074 , I mean just only like this http://mysite/bonus
    it works fine with that
    UncertaintyP
    @UncertaintyP
    Request::is('bonus*') should be enough
    ezekel
    @ezekel
    @UncertaintyP my URL looks like this http://mysite/group/10/bonus, the active class isn't applied
    http://mysite/group/10/5/edit, the active class isn't applied here too
    Ulrich-Matthias Schäfer
    @Fuzzyma
    @cbj4074 its the php development server. So its just the php executable. But jeah - its from apache. It shouldnt matter of html or php. It both doesnt work though :/
    ezekel
    @ezekel
    @UncertaintyP @cbj4074 , my problem is fixed now :)
    Ben Johnson
    @cbj4074
    @ezekel Thanks for the update... but how did you fix it?
    Ravelin
    @Ravelin
    Hi, can anyone help me. I'm trying to get the url of a public file from S3, the file is accessible outside the bucket, and it exists. But using Storage::disk('s3')->url($file) or Storage::cloud()->url($file) doesn't work. I've tried using getObjectUrl($file) also but i'm getting a null array error
    Ravelin
    @Ravelin
    Fixed, it was/is a php7.4 issue, rolling back to 7.2 fixed it. Now to work out why/what it's doing
    UncertaintyP
    @UncertaintyP
    If it doesn't work you usually just put it in rice or restart it. Works 60% of the time - every time
    Daniel Sánchez
    @panconjugo_twitter
    Hey guys, I need help setting up my server. I cloned a laravel project in a google cloud compute engine, but now I can see the code of the files when I navigate to the url, I think this is due to the permissions but I don't really know how to change them properly.
    Ben Johnson
    @cbj4074
    @panconjugo_twitter It sounds more like an issue with the files not being interpreted as PHP.
    Daniel Sánchez
    @panconjugo_twitter
    I just reinstalled php and now it worked, thanks for the reply @cbj4074
    Andrius Solopovas
    @asolopovas
    Guys does anyone know why my errors are displayed like that ?
    it started happening since upgrade to laravel 7
    Ben Johnson
    @cbj4074
    @panconjugo_twitter :thumbsup: Awesome!