Snapey

at Novate / Microlise

Hire Me

Experience

683,005

1040 Best Reply Awards

  • Member Since 3 Years Ago
  • 862 Lessons Completed
  • 1 Favorite

24th November, 2017

Snapey left a reply on Trying To Get Property Of Non-object • 8 hours ago

form request extends request so $this->brand is the same as doing $request->brand in the controller

whether you get anything back depends if you have a form input called brand

if you want the model ID then you need to look what you called it in the route

Snapey left a reply on Eager Loading Relationship Returning Entire Table • 8 hours ago

you just literally said get() on a story model, so all are loaded

use load instead

public function show(Story $story)
{
    return $story->load('comments');
}

Snapey left a reply on Laravel Second Task Schedule Never Runs • 10 hours ago

does queue:work actually return? is it not designed to keep running? your withoutOverlapping will leave a mutex behind that stops other schedules.

Snapey left a reply on Laravel Soft Delete Cascade • 15 hours ago

To soft delete relations, you have to do it using model observers

So if company is soft deleted, the 'deleted' event in the company model is hooked to also soft delete the domain(s) associated with company, and then in the Domain model, hook the deleted event so that projects are soft deleted, and so on down the chain of relations.

This is from L5.2; where CampaignEvent has Shifts and Shifts has Activities

CampaignEvent.php;

    //observe this model being deleted and delete the child shifts
    public static function boot ()
    {
        parent::boot();

        self::deleting(function (CampaignEvent $event) {

            foreach ($event->shifts as $shift)
            {
                $shift->delete();
            }
        });
    }

Shift.php

    //observe this model being deleted and delete the child activities
    public static function boot ()
    {
        parent::boot();

        self::deleting(function (Shift $shift) {

            foreach ($shift->activities as $activity)
            {
                $activity->delete();
            }
        });
    }

Snapey left a reply on [ErrorException] Symlink() Has Been Disabled For Security Reasons • 15 hours ago

You asked how to create symlink. Your ISP won't let you. I suggest you write the files that you would have put in the symlink folder, instead direct in the public area of the site so that a symlink is not required.

Snapey left a reply on [ErrorException] Symlink() Has Been Disabled For Security Reasons • 18 hours ago

put the files directly in public folder instead of storage

I assume because you are trying to create a symlink you are putting files in storage/app/public?

Snapey left a reply on BelongsToMany Optimizing With Currently Loggedin User • 18 hours ago

Can't be done in the code you have shown. We need to see the bigger picture and if, with the correct relationships you can use eager loading.

more like;

$sheeps = Sheep::with('herd')->get();   // hate that 'sheeps'

and then when iterating over the individual sheep, check if the sheep->herd->id is in an array of the user's herds

Snapey left a reply on N Days Difference In Two Date Fields • 18 hours ago

use DATEDIFF as per @Cinek suggestion, but use it in a where statement not a select

Snapey left a reply on [ErrorException] Symlink() Has Been Disabled For Security Reasons • 18 hours ago

Just store your files in the public folder as it is done on most of the sites on the web (e.g., every wordpress install)

Snapey left a reply on Pull Details From Another Model Based On Select Option While Filling Out Form • 1 day ago

One thing I would change is make this a GET request as you are not changing state in the server.

I'm not too hot on the javascript side but it looks a bit overly complicated compared to some implementations, particularly compared to when using vue

Your controller can be simplified quit a bit

public function customerDetails(Request $request)
{

        return Customer::findOrFail($request->customerID); 

}

Snapey left a reply on Error Updating Laravel 5.4 • 1 day ago

After composer has run it fires some artisan commands like @php artisan key:generate

being an artisan command, these boot your application to run

If there is something in your code that does not work correctly then the error will be thrown. The error may not show fully at this point but there should be a stack trace in your laravel log file so that you can work out which file is causing the issue.

The error is basically saying that you are using DB in a class that does not have a namespace, so it is no point having it there - more of a warning than an error.

23rd November, 2017

Snapey left a reply on Pull Details From Another Model Based On Select Option While Filling Out Form • 1 day ago

If its dynamic then an ajax call would be the way to go so that onChange of one field causes an ajax request to a route that provides the required data.

Snapey left a reply on ProductController GetProduct() Method (Query) Problem • 1 day ago

You have to get all the products for business and then loop over them creating a URL for each product

BusinessController

public function show(Business $business)
{
    Business::load('products');

    return view ('business.index')->withBusiness($business);

}

business/index.blade.php

<h1> products of {{ $business->name }}</h1>

<ul>
@foreach($business->products as $product)

    <li><a href="{{ route('product.show', $product }}">{{ $product->name }}</a></li>

@endforeach
</ul>

ProductController

public function show(Product $product)
{
    
        return view('product.show', compact('product'));
}

Web.php

Route::get('/business/{business}' [email protected]')->name('business.show');

Route::get('/product/{product}',[email protected]')->name('product.show');


but really the above is all guess work because we don't really know what your data looks like or what you want to do

22nd November, 2017

Snapey left a reply on MethodNotAllowedHttpException - No Message • 2 days ago

if you want to check the names of routes, use php artisan route:list

Its a security enhancement that the logout route is POST and not GET, so, it may have just worked before but things move on...

Snapey left a reply on Call To A Member Function HasRole() On Null • 2 days ago

try flipping the logic and also checking if logged in

    public function handle($request, Closure $next, ...$role)
    {


        if (Auth::check() && in_array($request->user()->hasRole(), $role)) {

            return $next($request);

        }

        return view('nopermission');

    }

Snapey left a reply on Access Global Scope Relationship? • 2 days ago

Yes, its ok, but the point is, if its a one to many, and we just pick the first value, what about the other values?

Snapey left a reply on Access Global Scope Relationship? • 2 days ago

If user_discpline is any array (of relations), i.e. a one to many relationship then you could have multiple values.

Do you have the same issue with $user->userDiscipline->first()->value

Snapey left a reply on Upload Files In Loop: "not Uploaded Due To An Unknown Error." • 3 days ago

@arunmadathil unless you have written exactly the same problematic code, start your own thread.

Snapey left a reply on Bootstrap In Laravel 5.5 • 3 days ago

The boilerplate layouts/app.blade.php loads the pre-built /public/css/app.css and /public/css/app.js files, both of which contain bootstrap v3.3.7

Snapey left a reply on Unable To Upload File On Server : Failed To Open Stream: Is A Directory • 3 days ago

I think the problem is possibly also that your filename contains spaces but when you use it you are not quoting the filename

try with a filename that does not have any spaces

I also notice that this line; $data = Request::get('file'); is unlikely to work unless the file is actually called 'file' with no path...

21st November, 2017

Snapey left a reply on 'log_max_files' Not Functioning Properly? • 3 days ago

are your logs created by scheduled jobs? I'm not sure how they are housekept but maybe they are not owned by the web server and therefore cannot be deleted?

Snapey left a reply on Check If Password Has Been Used Before • 3 days ago

its not possible to a straight forward comparison

get all the previous passwords for the given user then each over them using the hash check function

if (Hash::check('plain-text', $hashedPassword)) {
    // The passwords match...
}

if the check returns true then the user is trying to reuse a previous password

Snapey left a reply on Access Global Scope Relationship? • 3 days ago

what about user->user_discipline->value

Snapey left a reply on List [Tag] Model With Tag Counter • 3 days ago

so you have a pivot table then?

Snapey left a reply on Access Global Scope Relationship? • 3 days ago

actually in all versions of php, you can also use Blade's or operator

<td>{{ $user->userDiscipline or '' }}</td>

20th November, 2017

Snapey left a reply on About View Composers - Cannot Get It To Work - Laravel 5.5 • 4 days ago

try view->share(compact('results')); instead of view->with()

Snapey left a reply on Grouping Routes Not Working As Expected • 4 days ago

oh, in your original question were 'route1Controller' and 'route2Controller' actually the same controller?

Snapey left a reply on Access Global Scope Relationship? • 4 days ago

whenever you loop over a set of data you have to beware of one or more of those relationships being missing.

This can be confusing because if you stick a dd into the loop it will stop on the first record and that one can appear ok.

to code defensively make sure there is a fallback in case of missing relations. For instance;

<td>{{ $user->userDiscipline->value ?? '' }}</td>

here the php7 null coalesce operator is used (??) and will use the second value if the first is null.

Snapey left a reply on Integrate Google Analytics Into Dashboard • 4 days ago

iframe?

Snapey left a reply on Redirecting After Authentication Not Working • 4 days ago

where do you end up after logging in?

open your browser network tools and check for any redirects

Snapey left a reply on Can't Find Access_token And Refresh_token On Request • 4 days ago

there are no such tokens? there is a csrf token and a session cookie.

You can obtain an access token if you implement Passport but it doesn't happen automatically

Snapey left a reply on Grouping Routes Not Working As Expected • 4 days ago

the bit i'm unsure about is the use of the 'splat' operator in the middleware.

in the route group you are passing an array to the middleware, but when adding it as a parameter to the route you dont pass as array?

Snapey left a reply on Is There A Way To Get Rid Of The Need For The Full Path When Accessing Model In A Blade? • 4 days ago

ideally you would pass all data needed into the view.

Alternatively write a helper function or use a view composer

Snapey left a reply on Call To A Member Function GetChildren() On Null • 4 days ago

my list makes as much sense as your question

Snapey left a reply on Call To A Member Function GetChildren() On Null • 4 days ago

  • potatoes
  • carrots
  • peas
  • milk
  • cheese

Snapey left a reply on Saving Inputs To Different Database Table • 4 days ago

Sounds like you are not ready to mess with cashier. I would start with some basics.

Snapey left a reply on Method Not Allowed • 4 days ago

also, general question why do people use the Form helpers they seem to make things harder to read and don't seem to provide much benefit. it actually seems like there are more characters. than just <form ...>

amen to that ....

It seems like a crutch that just makes you walk funny.

Snapey left a reply on Image Upload With Pivot Table (foreach Loop) • 4 days ago

Great. How did you manage to get the images? I can't see anything here that would resolve the problem?

Snapey left a reply on List [Tag] Model With Tag Counter • 4 days ago

So a post can only belong to one tag?

Snapey left a reply on List [Tag] Model With Tag Counter • 5 days ago

what models and relationships do you have?

Snapey left a reply on Automatic Ajax Request • 5 days ago

i tried all steps mention above but i am not getting value in controller

how do you know?

19th November, 2017

Snapey left a reply on 3 Way Pivot Table Or Complex Relationship • 5 days ago

the reverse relationships can be made with hasMany

Snapey left a reply on About View Composers - Cannot Get It To Work - Laravel 5.5 • 5 days ago

your classname doesn't match? However i'm surprised this does not throw an error

Snapey left a reply on 3 Way Pivot Table Or Complex Relationship • 5 days ago

@robrogers3 I'm illustrating the principle not the specific relationships. btw you have an error in your example. No need to pass anything into the relationship.

Snapey left a reply on Keeping Correct Data On Views • 5 days ago

@design-studio good call, i missed that. Yes, never return a view in response to a POST request. Always redirect somewhere else.

The cause of some of the errors makes sense now

   public function softDelete(User $user)
    {
        //deleting the user contained in it's own instance, soft delete
       $user->delete();
        return view('home', compact('users', 'trashed_users'));
        //returns the view
    }

nothing here to initialise the users or trashed_users

@jordano1 remember that each request, GET or POST, is a completely new request cycle. The only things that survive are things saved in Session.

Snapey left a reply on Image Upload With Pivot Table (foreach Loop) • 5 days ago

Can't see anything wrong there.

Try with your dd at the top of the request.

How come your form posts to '/success' but the method is postProduct ?

Do you submit the form with traditional post or are you submitting with ajax

Snapey left a reply on Image Upload With Pivot Table (foreach Loop) • 5 days ago

I replicated your code, pointed it at a controller and put dd($request->images); at the top

This is what I see.

Puzzled why you only see filenames. What is going on in the rest of the controller?

array:3 [▼
  0 => UploadedFile {#198 ▶}
  1 => UploadedFile {#204 ▶}
  2 => UploadedFile {#205 ▶}
]

Snapey left a reply on How To Get Value From Textarea? • 5 days ago

What is the class Textarea?

Try dumping the value to check what you get at the server

Route::post('insert_user_info', function(){

    dd($request->description);

})->name('insert_user_info');

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.