Snapey

at Novate / Microlise

Hire Me

Experience

558,435

865 Best Reply Awards

  • Member Since 2 Years Ago
  • 808 Lessons Completed
  • 1 Favorite

28th July, 2017

Snapey left a reply on L5 - CSRF Token Refresh Approach • 1 hour ago

@devlanga You have to catch the error and return the user to a fresh copy of the form (probably with an apology notice)

Snapey left a reply on TokenMismatchException • 2 hours ago

is it only when you attach a large file?

by the way, this url: '/mway/public/getCityList/'+stateID, is going to cause you problems because

a) this shows me that your site is incorrectly setup and public is present in your routes. This needs to be fixed

b) you won't be able to publish your site without going through all of your code and fixing the routes.

Snapey left a reply on L5 - CSRF Token Refresh Approach • 2 hours ago

@devlanga Don't leave the user on a page containing a form. Redirect them where possible to a page with no form. e.g., after logout.

Snapey left a reply on Eager Loading With Constrain • 2 hours ago

don't you need to pass $resume through?

Snapey left a reply on Mb_strpos() Expects Parameter 1 To Be String, Object Given • 2 hours ago

so, nothing to do with the original post then, you have abandoned eloquent?

by the way, you cannot use groupBy with paginate (although I see that is commented out)

If any of your rows are one to many then you will have duplicated columns.

Snapey left a reply on How To Return One Row From BelongsToMany ? • 2 hours ago

wtf are you on about.

27th July, 2017

Snapey left a reply on How To Return One Row From BelongsToMany ? • 10 hours ago

I give up

Snapey left a reply on Laravel 5.4, Maximum Function Nesting Level Of '256' Reached • 10 hours ago

have you used $with in any of your models?

Snapey left a reply on Log Out When Session Expires • 10 hours ago

The user IS logged out when the session expires. Do you mean at the browser?

Snapey left a reply on Is Session Active • 10 hours ago

Basically the answer is no

If you could write such code, where would you run it?

What would trigger it to run?

Snapey left a reply on FindOrFail Not Throwing 404 Exception • 10 hours ago

have you set public $incrementing=false; on your model?

Snapey left a reply on Whoops Something Went Wrong! • 11 hours ago

Because you probably show something in the page header that relies on being logged in, such as route('user.update') for instance.

If the user is a resource controller, the route() command will attempt to get the userID to include in the URL.

Anything like this you should step over with @if(Auth::check()) or similar

Snapey left a reply on FindOrFail Not Throwing 404 Exception • 11 hours ago

$industry = Industry::findOrFail($id); should work?

Snapey left a reply on How To Return One Row From BelongsToMany ? • 11 hours ago

@jlrdw Nothing to do with checkboxes as far as I'm aware

There is a bunch of images in one model. There are 5-10 (whatever) categories in another model.

The user says show me pictures with categories of 'history' and 'landscape' (might be selected by checkbox, by typing or by multi-select etc etc - this is not the consideration).

The OP says when searching for pictures in the category of History, and then searching for pictures in the category of landscape, the same picture appears twice, since it is present in both category.

So in your logistics example, your query said, get me any shipment where the bill to was Mark and also any shipment where the ship to was Mark.

Then you look down the report and you say hang on, row 2 and row 5 are the same shipment number - because on one shipment Mark was both the ship To and the bill To

@frogeyedman - sorry for the distraction....

Snapey left a reply on How To Return One Row From BelongsToMany ? • 12 hours ago

@jlrdw - still missing the point I think ;-)

@frogeyedman my code should do what you need and give you a collection of pictures that match the category names that I put in the $searching array. You would have to decide how you populate the array.

My code uses eager loading wheres doing it the way you suggest will give an n+1 issue as the database has to be queried for every pass through your foreach loop.

Snapey left a reply on BelongsToMany Fires Query With Id 0 • 13 hours ago

as you don't follow convention you probably need to fully specify foreign keys in each relation

Snapey left a reply on Adding Check On Auth Login • 13 hours ago

i think it's just $this->username now, but you can leave this out, all it does is redirect back to the login page with the username pre-filled

Snapey left a reply on How To Return One Row From BelongsToMany ? • 14 hours ago

perhaps;

$searching = ['history', 'landscape'];

$pictures = Picture::whereHas('category', function ($query) use($searching) {

    $query->where(1,1)  // so we can use orWhere in the loop

    foreach($searching as $term) {
        $query->orWhere('name', $term);
    }

})->get();

Snapey left a reply on How To Return One Row From BelongsToMany ? • 14 hours ago

first thought is that you need to deduplicate the result - but first, you don't load any pictures?

Snapey left a reply on Array And Multiple Inserts • 14 hours ago

You pass an array into the create method, specifying the array element needed

suppose you have a Reminder model

$reminder = Reminder::create([
    'remind_on' => $vaccine['parvovirus_date'],
    'free_text' => $vaccine['parvovirus_text'],
    'wants_reminder' => $vaccine['parvovirus_reminder'],
    ]);

and I guess you repeat for each type

Snapey left a reply on Adding Check On Auth Login • 14 hours ago

Then I'm afraid you have to take a different approach since the one shown just adds a where condition to the auth attempt.

Also in the AuthenticatesUsers trait there is an authenticated method.

What you have to do is allow the user to login, then in the authenticated method, flash your message and log them out again.

I won't duplicate a previous answer; https://laracasts.com/discuss/channels/laravel/laravel-authenticated-not-working

Snapey left a reply on Why Does Eloquent Select All? • 14 hours ago

this select * from "users" where "id" = '1' limit 1

occurs on any request where the authenticated user is needed

How else? Would you prefer an additional call if it turned out a moment later that you wanted for example Auth::user()->email

besides this would make zero difference to the query execution or memory.

On your other example, if select * from "users" is being executed then it will be in your code somewhere and you are not using one of the several methods available for requesting specific columns.

Snapey left a reply on @forelse "No Books" • 14 hours ago

I am embarrassed to say that right now i do not know what i am doing.

As demonstrated..

Snapey left a reply on Reseting Environment Lock Key? • 14 hours ago

Sorry, completely missed that this question was in the envoyer topic!

Snapey left a reply on Adding Check On Auth Login • 14 hours ago

Yes, don't follow that advice.

The function you are replacing is in a trait and a method in the class itself will always take precedence over the same named method in the trait.

So, you can add what you need to the app\Http\Auth\LoginController.php and it won't be overridden in the future.

The example provided should work if you have a 'verified' column

protected function credentials(Request $request)
 {
 return array_merge($request->only($this->username(), ‘password’), [‘verified’ => 1]);
 }

Snapey left a reply on TinyMCE Editor - Unable To Post • 14 hours ago

adding 'required' to the form just means that the user cannot press submit before putting something in that field. Its got nothing to do with security. Adding it or removing it makes no difference.

Snapey left a reply on Reseting Environment Lock Key? • 14 hours ago

just delete the file? But what's an "environment lock key"

Snapey left a reply on $bgprofile Is Undefine • 14 hours ago

If you type http://localhost/soulfy_repo/public_html/home/bgprofile in your browser then this is a GET request.

Change the route to;Route::get('home/bgprofile', ['uses' => [email protected]']);

Then, your form action needs to be another method, for which you will want the POST route

Snapey left a reply on Why Is It Bad Idea To Use Request::isJson Instead Of API Route? • 21 hours ago

Only you can make that decision. You do need to be sure that your service is used appropriately and securely (and not just adopt security by obscurity)

Snapey left a reply on Mb_strpos() Expects Parameter 1 To Be String, Object Given • 1 day ago

looks like you solved it in the new thread

Snapey left a reply on Laravel . Cron Vs Queue • 1 day ago

Why do you need a queue? You are thinking that after 1 minute the post is set to published?

You could just set a publishedcolumn as a date time instead of a state and then set it in the future by a little while, then when looking for posts you check if it is published by checking if the published date is in the past.

I'm not saying not use a cron, that is also an option, but you would not check ALL 10000 posts, you only check for the few that are waiting and you can get these with one simple query that uses an indexed column with the right search terms.

Snapey left a reply on $bgprofile Is Undefine • 1 day ago

@davy_yg oh dear - three months in and still no wiser

I am using many controller in one page. Is that ok?

Its very clever if you are...

in your view write <?php dd($bgprofiles); ?> somewhere near the top (note it ends in an s)

and then change this

@foreach ($bgprofile->chunk(3) as $chunk)

to

@foreach ($bgprofiles->chunk(3) as $chunk)

note that bgprofiles ends in an s

Snapey left a reply on Mb_strpos() Expects Parameter 1 To Be String, Object Given • 1 day ago

So what does your code look like now?

26th July, 2017

Snapey left a reply on Custom Eloquent Query • 1 day ago

can you put three backticks ``` before and after your code?

Eloquent is an ORM - you have to think in terms of objects and relationships.

If you want to think in terms of SQL statements then you are better with the query builder and the DB:: facade

You can always execute raw sql with DB

Snapey left a reply on Why Is It Bad Idea To Use Request::isJson Instead Of API Route? • 1 day ago

API routes are segregated because it is expected to use different authentication methods and to not use session management.

If you want to use sessions then I would stick with web.php and if you want to use passport or token authentication (stateless requests) then use api.php

At least thats the way I understand it

Snapey left a reply on TinyMCE Editor - Unable To Post • 1 day ago

check the browser console for errors

Snapey left a reply on How To Return An Array With Redirect()->back()->with('',[$a]); • 1 day ago

What were you expecting?

Snapey left a reply on Trying To Get Property Of Non-object • 1 day ago

The value goes between the option elements (as I showed)

<option value="{{$key}}">{{$template}}</option>

Snapey left a reply on Laravel Back() Function • 1 day ago

good luck.

Why don't you just redirect to where you want users to go...?

Snapey left a reply on TinyMCE Editor - Unable To Post • 1 day ago

one issue

<form class="form-horizontal"  method="post" action="{{route('admin.store')}}" enctype="multipart/form-data">

form-data not form=data

other than that, you are going to have to say what happens and not just 'unable to post'

Snapey left a reply on How To Return An Array With Redirect()->back()->with('',[$a]); • 1 day ago

print_r ?

    $msg= "Data inserted for record id: {$row['record_id']}";

    return redirect()->back()->with(compact('msg');

Snapey left a reply on Trying To Get Property Of Non-object • 1 day ago

$templates is a non-object

It is an array - use array syntax with it.


<form method="POST" action="{{route('product_create')}}">
            {{csrf_field()}}
            <select class="form-control" name="template">
                @foreach($templates as $key =>$value)
                    <option value="{{$key}}" >{{$value}}</option>
                @endforeach
            </select>
            <input class="btn btn-primary" type="submit" value="Product toevoegen">
        </form>

can't help you with the selected part because I don't know what you are trying to check.

By the way you could have just used an object...

Snapey left a reply on @forelse "No Books" • 1 day ago

If it is just the last book then in the controller

$book = Book::latest()->first();

will get just one book from all the books.

You say that you want to check if you have no book - are you filtering the books in some way (e.g. by category) I can't imagine you would not have one book ?

Anyway, supposing you can have no book then

@isset($book)
    // you have $book, display $book->description etc
@endisset

@empty($book)
    // you have no book - say what you want
@endempty

Snapey left a reply on How To Check Whether A Route(URL) Is An Asset Route? • 1 day ago

because your .htaccess file will forward requests for missing objects to your index.php file. This in turn will send back a 404 error because you have no route for favicon.ico

If you had a favicon this particuar issue would not happen

Snapey left a reply on Update Data Using Array • 2 days ago

no, do it in the actual loop - don't create another loop!

and don't bother with creating a $data array

public function UpdatePermission(Request $req)
{
    for ($i=0; $i<count($req->roleid); $i++) {

        DB::table('permission')
            ->where('per_id',$req->perid[$i])
            ->update([
                'per_roleid' => $req->roleid[$i],
                'per_pageid' => $req->pageid[$i],
                'view' => $req->view[$i],
                'add' => $req->add[$i],
                'edit' => $req->edit[$i],
                'delete' => $req->delete[$i],
 
        ]);

    } 
    return redirect()->back();
}

no point in copying stuff around the place needlessly,

Snapey left a reply on Mb_strpos() Expects Parameter 1 To Be String, Object Given • 2 days ago

I don't know but I would probably change this;

$resume->whereUserId(3);

to this;

$resume->where('userId',3);       // or where('user_id',3) as appropriate

since I'm never so sure of 'magic' wheres when the column name is camel cased or snake cased.

Snapey left a reply on How To Check Whether A Route(URL) Is An Asset Route? • 2 days ago

What you are doing is fundamentally flawed anyway since a user can have two browser tabs open, on the same session, and on totally different pages.

Snapey left a reply on Update Data Using Array • 2 days ago

As you are iterating over the request anyway, write one row per loop to the database and not try to bulk insert.

25th July, 2017

Snapey left a reply on How To Get Posts Via Category With Pagination • 2 days ago

pagination will apply to the Category model

you need to turn it around and query posts having category of 1, 2 or 3 (whereHas)

https://laravel.com/docs/master/eloquent-relationships#querying-relationship-existence

Edit Your Profile
Update

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