vincej

Experience

36,500

2 Best Reply Awards

  • Member Since 3 Years Ago
  • 158 Lessons Completed
  • 18 Favorites

18th May, 2017

vincej left a reply on Custom Validation Attributes Does Nothing... • 1 week ago

@bobbybouwmann

Hi ! I need some advice with how to change the attributes on a dynamic array with the only identifier is an ID number I am validating an array like this ( this works):

  $messages = [
            'required' => 'The :attribute field is required!',
        ];


        $validator = Validator::make($request->all(),
            [
                'cat_name.*'=>'required|max:20',
                'notes.*'=> 'required|max:200'
            ],

        $messages

        );


        if ($validator->fails()) {
            return redirect('edit_categories')
                ->withErrors($validator)
                ->withInput();
        }

But the error messages look terrible. As you can see it uses the field name:

    The cat_name.25 field is required!
    The notes.1 field is required!
    The notes.25 field is required!

There are many rows to the form, so it would be useful to be able to advise, "Category Name with ID 25 is Required"

Can it be done ?

Heel veel bedankt !

Many Thanks !!

vincej left a reply on How To Get Required $_POST Into Required Shape For Array Validation ? • 1 week ago

@jlrdw I like the approach !

But what is this: Cln::fixValue I have not seen this before.

vincej left a reply on How To Get Required $_POST Into Required Shape For Array Validation ? • 1 week ago

@snapey @bunnypro @jldrw

I go it ! Blade does not like the double braces {{}}. Also I changed it to a foreach loop. You have to put quotes and concatenate inside the the [id] name of the input field. The docs are

This works, and validation is now also working !!! I now need to customise the messages - joy :) Anyone who says Laravel is easy to use is talking out their butt. CodeIgniter is easy, but relatively lightweight compared to Laravel.

Many thanks !

 <tbody>
        @foreach($categories as $category)
        <tr>

 <td>{!! Form::text('cat_name['.$category->category_id.']',$category->name)!!}</td>
            <td>{!! Form::textarea('notes['.$category->category_id.']',$category->notes])!!}</td>
            <td>{!! Form::select('status[]', ['active'=>'Active' ,'deactivate' => 'Deactivate', 'delete' => 'Delete'],$category->status , ['class'=>'edit_cat form-control'])!!}</td>
    
 </tr>
        @endforeach
        </tbody>

vincej left a reply on How To Get Required $_POST Into Required Shape For Array Validation ? • 1 week ago

Thanks guys, I have tried putting the {{$i}} counter inside the blade syntax but, Blade will not render the statement.

Furthermore, as my controller is submitting to the view a collection which I loop over, I have to include $categories[$i]->namewithin the Blade statement like this:

<td>{!! Form::text('cat_name[]', $categories[$i]->name,)!!}</td>

vincej started a new conversation How To Get Required $_POST Into Required Shape For Array Validation ? • 1 week ago

The docs stipulate that in order to validate an array, the POST must to fit into this shape: https://laravel.com/docs/5.4/validation#validating-arrays

$validator = Validator::make($request->all(), [
    'person.*.email' => 'email|unique:users',
    'person.*.first_name' => 'required_with:person.*.last_name',
]);

or as Matt Stauffer explains: https://mattstauffer.co/blog/form-array-validation-in-laravel-5-2

array(2) {
  ["name"]=>
  string(10) "Acme, Inc."
  ["employee"]=>
  array(2) {
    [1]=>
    array(2) {
      ["name"]=>
      string(10) "Joe Schmoe"
      ["title"]=>
      string(11) "Head Person"
    }
    [2]=>
    array(2) {
      ["name"]=>
      string(18) "Conchita Albatross"
      ["title"]=>
      string(21) "Executive Head Person"
    }
  }
}

Question:

So, when I submit my view with all the form entries, I can not see how to structure data so that it will fit this required shape. I have tried both foreach and a for loop. This is what I have got. HOw do I reshape my form so that when it is submitted it fits the required shape for validation?

 <tbody>
        @for($i=0; $i<$count; $i++)
        <tr>
            <td>{!! Form::text('cat_name[]', $categories[$i]->name,  ['class'=>'edit_cat form-control'])!!}</td>
            <td style="text-align: center">{!! Form::textarea('notes[]',$categories[$i]->notes,['class'=>'form-control','id'=>'notes','rows'=>'1'])!!}</td>
            <td style="text-align: center">{!! Form::select('status[]', /*$categories[$i]->status,*/['active'=>'Active' ,'deactivate' => 'Deactivate', 'delete' => 'Delete'],$categories[$i]->status , ['class'=>'edit_cat form-control'])!!}</td>
        </tr>
        @endfor
 </tbody>

It produces an array like this:

array:5 [▼
  "_token" => "C2xi6sLilJVQecfQ4UfrMf4ngGwTY1rEOOSe8Qki"
  "cat_id" => array:4 [▼
    0 => "26"
    1 => "24"
    2 => "1"
    3 => "25"
  ]
  "cat_name" => array:4 [▼
    0 => "cedar"
    1 => "Materials"
    2 => "Products"
    3 => "slate"
  ]
  "notes" => array:4 [▶]
  "status" => array:4 [▶]
]

17th May, 2017

vincej left a reply on How To Validate Array From View - I Keep Getting An Error Message. • 1 week ago

No matter what I do I end up with a POST array that looks like this:

array:5 [▼
  "_token" => "93sfV3Lvtx2weQa5XgxJGyIVkV5Nv9qbAcuDtcSM"
  "cat_id" => array:4 [▼
    0 => "26"
    1 => "24"
    2 => "1"
    3 => "25"
  ]
  "cat_name" => array:4 [▼
    0 => "cedar"
    1 => "Materials"
    2 => "Products"
    3 => "slate"
  ]
  "notes" => array:4 [▶]
  "status" => array:4 [▶]
]


vincej left a reply on How To Validate Array From View - I Keep Getting An Error Message. • 1 week ago

too right ! :)

thanks for the code.

I am going to try running the POST data through a foreach and validating one by one like you suggest.

vincej left a reply on How To Validate Array From View - I Keep Getting An Error Message. • 1 week ago

Good idea, I will think on that. I could also take the easy way out and use the either js validation or even HTML5 validation.

vincej left a reply on How To Validate Array From View - I Keep Getting An Error Message. • 1 week ago

@jldrw Thank you very much for your suggestion.

I have spent the day studying Matt's format very carefully, and trying all kinds of things out built on his code. Sadly, all to no avail. The irony is that the L5.4 docs actually make the comment:

"Validating array based form input fields doesn't have to be a pain"

Well, I hate to say it, but it is nothing but a major pain.

The problem lies in the fact that in order to make array validation work, the $_POST has to be in a very specify format. Any deviation and validation fails. It should be easy, but, nope, I've tried using Blade and raw PHP and it beats me.

Matt's example, assumes that you are building a straightforward input form with multiple rows:

<input type="text" name="employee[2][name]">

Getting this into a format which Blade can handle using a for loop, as I have multiple dynamic values, and which in turn spits out the correct shape of the $_POST array is anything but easy. I have also tried using raw PHP, and can't get the POST array right.

It has to look like this:

array(2) {
  ["name"]=>
  string(10) "Acme, Inc."
  ["employee"]=>
  array(2) {
    [1]=>
    array(2) {
      ["name"]=>
      string(10) "Joe Schmoe"
      ["title"]=>
      string(11) "Head Person"
    }
    [2]=>
    array(2) {
      ["name"]=>
      string(18) "Conchita Albatross"
      ["title"]=>
      string(21) "Executive Head Person"
    }
  }
}

cheers !

vincej started a new conversation How To Validate Array From View - I Keep Getting An Error Message. • 1 week ago

Using 5.4

My view is made up of many dynamically created rows all containing data with the same name:

  <tbody>
 @foreach($categories as $category)
        <tr>
             {!!Form::hidden('cat_id[]', $category->category_id)!!}
            <td>{!! Form::text('cat_name[]',$category->name,['class'=>'edit_cat form-control'])!!}</td>
            <td style="text-align: center">{!! Form::textarea('notes[]',$category->notes,['class'=>'form-control','id'=>'notes','rows'=>'1'])!!}</td>
            <td style="text-align: center">{!! Form::select('status[]', ['active'=>'Active' ,'deactivate' => 'Deactivate', 'delete' => 'Delete'],$category->status , ['class'=>'edit_cat form-control'])!!}</td>
        </tr>
        @endforeach
  </tbody>

It all works great, until I try to validate the data:

  $validator = Validator::make($request->all(),
            [
                'cat_name.*'=>'required|max:20',
                'notes.*'=> 'max:200'
            ]
        );

        if ($validator->fails()) {
            return redirect('edit_categories')
                ->withErrors($validator)
                ->withInput();
        }

If I intentionally create an error, I get an error message:

ErrorException in helpers.php line 533: htmlspecialchars() expects parameter 1 to be string, array given

I have removed all of the escaping from my form, so I have no idea why htmlspecialchars is being invoked. Posts on SO suggest that the select is to blame .. but if I comment it out, it makes no difference. If I comment out validation, then my updates work.

If I do a dd($errors) I am getting the errors through.

ViewErrorBag {#392 ▼
  #bags: array:1 [▼
    "default" => MessageBag {#393 ▼
      #messages: array:1 [▼
        "cat_name.0" => array:1 [▼
          0 => "The cat_name.0 field is required."
        ]
      ]
      #format: ":message"
    }
  ]
}

What am I doing wrong ??

Many thanks !!

12th May, 2017

vincej left a reply on How Best To Save Multiple Rows Of Table Data Into The DB • 1 week ago

hmm .. I could try putting the $category_id into the ` like this:

<td id =$category_id> <td>

Then in the controller, group by category_id before saving.

I'll give it a try. Thanks

vincej left a reply on How Best To Save Multiple Rows Of Table Data Into The DB • 1 week ago

@MaverickChan using 5.4

A more traditional way ?? Can you please give me a hint what you mean. Perhaps not using a table, but rather a series of text inputs ?

vincej started a new conversation How Best To Save Multiple Rows Of Table Data Into The DB • 1 week ago

Essential Question: How to upload my table data so it can be correctly saved?

Within my view, I have a table with 3 columns and multiple rows. The rows are populated correctly with a foreach:

 <tbody>
        @foreach($categories as $category)
        <tr>
            {!! Form::hidden($category->category_id)!!}
            <td>{{Form::text('cat_name[]',$category->name,['class'=>'edit_cat form-control'])}}</td>
            <td style="text-align: center">{{ Form::textarea('description[]',$category->notes,['class'=>'form-control','id'=>'notes','rows'=>'1'])}}</td>
            <td style="text-align: center">{!!Form::select('amend[]', ['active'=>'Active' ,'deactivate' => 'Deactivate', 'delete' => 'Delete'], 'Active', ['class'=>'edit_cat form-control'])!!}</td>
          
        </tr>
        @endforeach
        </tbody>

The user can change the spelling of a category name, or add a comment, or deactivate the category through a select drop down.

Great - so now I want to upload the form with all the changes and save the data to my DB. Somewhere I remember that you need to convert each named field into an array, hence why I applied [] to all the field names. However, note, it makes zero difference to the success / failure of my task.

When the data comes into the controller using this: $input = $request->all(); I am not getting a well organised series of arrays. My data:

array:13 [▼
  "_token" => "DKwMRNVqSvrOraEXdARba05b99WSWlaFqcMOxMVI"
  15 => null                             // This is a category id number 
  "cat_name" => array:9 [▼
    0 => "Architectural"
    1 => "Asphalt"
    2 => "Ceder"
    3 => "Hardware"
    4 => "Laminated"
    5 => "Materials"
    6 => "Nails"
    7 => "Roofing"
    8 => "Rubber"
  ]
  "description" => array:9 [▼
    0 => "Here is a nice comment"
    1 => "Another nice comment"
    2 => null
    3 => null
    4 => null
    5 => null
    6 => null
    7 => null
    8 => null
  ]
  "amend" => array:9 [▼
    0 => "active"
    1 => "active"
    2 => "active"
    3 => "active"
    4 => "active"
    5 => "active"
    6 => "active"
    7 => "active"
    8 => "active"
  ]
  13 => null
  22 => null
  14 => null
  16 => null
  10 => null
  17 => null
  12 => null
  20 => null
]

As always - Many Thanks !!

5th May, 2017

vincej left a reply on How To Change CSRF Token And /or Session Data After Password Change ? • 2 weeks ago

Yes ! That worked. thanks !

btw - did you know I am a dual national? Lived in Herts for 26 years. British wife, kids and British Education.

vincej left a reply on How To Change CSRF Token And /or Session Data After Password Change ? • 2 weeks ago

@snapey

Success ! Many Many Thanks !!

I had to make a couple of mods to your code:

$request->user->password came back with:

Trying to get property of non-object

I checked with Storm debugger and found nothing, So I changed that bit back.

Then on the very last statement, it was puking with a redirect, so I changed that to a return and it worked: return view('contractor_portal/change_password',compact('name'));

Changing Subjects I notice that good developers like you write much more abbreviated code. I really want to be able to do the same, but I am having a real problem finding all these little cool functions like back() or fill() or what ever. I am reading the source code more and more, and I see these little funky functions all over the place. But I find looking them up in the API is major pain. I can spend 10 mins before I find it. The search function in the API is not the easiest. And then it is still not clear what they do. Perhaps I was spoilt during my CodeIgniter years when everything was searchable in seconds. I bought Matt Stauffers book who also admits that he learned loads of new things about Laravel during it's writing. If Matt learns new stuff, people like me are really going to have to work hard.

Question How did you find out about all this stuff ?? Does a person really have to digest the source code? I don't know if I have the stomach for that. Any tips / advice ? How did you do it ?

Thanks !

vincej left a reply on How To Change CSRF Token And /or Session Data After Password Change ? • 2 weeks ago

@snapey Thanks for your rapid reply !

This is how my controller works so far. I am not doing anything with the guard or csrf:


    public function password_update(Request $request){

        $this->validate($request,
            [
                'old_password'  => 'required',
                'new_password'  => 'required',
                'new_password2' => 'required|same:new_password',
            ]);

        $user = User::find(Auth::id());

        $old_password1 = $user->password; // From DB

        if(password_verify($request->old_password,$old_password1)) {
            $new_password = hash::make($request->new_password);
            $user->password = $new_password;
            $user->save();
            flash::success('Password has been updated');
            return view('contractor_portal/change_password');
        }
        else {flash::error('The Old Password is Not Valid');}


    }


vincej started a new conversation How To Change CSRF Token And /or Session Data After Password Change ? • 2 weeks ago

I have built a feature where a user can change their password after having logged in. (I am aware of reset pw feature, however that assumes you are not yet logged in yet.)

Ok - so I have my change password view working great. Also my change pw controller is working great. My controller checks the old password from the DB against the submitted pw in the form and then proceeds to hash and save a new pw. All Good !

Problem: Once the password has been changed, if I now go to another page on the site, Laravel kicks me out to the login page. I am guessing that this is because there is a now mismatch either with the CSRF token or perhaps more likely, the default web guard session data as created within the config/Auth. I don't know either way.

Any ideas nad help as to what I need to do to ensure that once a pw change has occured that the user will not get kicked out ?

Many thanks !

29th April, 2017

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@jimmck Once again, many thanks for al your help and feedback!

However, you have got me very wrong, I am actually very chill and not frustrated at all. Just always eager to overcome obstacles and always learn more. I am most certainly not a beginner. Perhaps that might give that impression, but that might be because a raging detail person.

My application as it stands today is many, many thousands of lines of Laravel, Javascript and Jquery code. Out of the box Authentication as given in the user docs is a walk in the park. That is not the challenge I am trying to overcome. I am wanting to deliver multi-authentication with multiple user types, and very specific user login and logout pages. Everything I have read and watched states that Laravel has major, major weaknesses in this area. Indeed some commentators state it can not be done with Laravel's current authentication structure, such is the gravity of the challenge. This is not only my opinion but the opinion of many commentators, and looking at the dialogue over the last 2 pages, it appears that reality is borne out. However, I have an idea on how to overcome the challenge. I'm optimistic.

Lastly, in my effort to accelerate my learning of Laravel, I have been searching through the API docs as you recommend. As already stated, I find these too not very accessible.

As always, many thanks for all your help, time and support!!

28th April, 2017

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@jimmck yup, for the last few w3ks I have been studying the API together with the source. I just wish it was easier to find what you are looking for in the API. I can waste 10-15 mins trying to find a single method. Any tips on how to find stuff quickly?

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@snapey @jfadich

Guys, my wife has just called me, and demands I come home as it's Fri. Heaven knows how late it is in the UK, 11.20pm! so I will have to suspend this conversation till monday. I hope you guys will bear with me, as truly, multi- authetication is a major pain in Laravel no one so far has managed to help me fix this. I have even tweeted Taylor about it. I'm hoping he will blog about it next week. It appears that most people just use 2 login screens and 2 logout screens which for me is really messy.

As always Many Thanks, have a good one !!!

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@snapey ok, can I extract the name from this ?

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@jfadich the guard layout is posted on page 1. I apply the guard middleware in the controller thus:

   public function __construct(){

        $this->middleware('auth:admin');
    }

@Snapey I have no idea why at the point of logout it should be coming out as web when I have been using an admin guard. The logout route has no middleware attached to it.

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@snapey no, web is the default guard which I use for "users" who login through the users login. admin guard is for the admins. I have posted my guard set up above. For clarity, if I log out of the admin side I want to be redirected to the admin login page. To achieve this, I want to be able to test for which guard is in use.

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@snapey for clarity, Auth::guard()->getName() returns

login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@Snapey, like I said above it does not test for 'admin'. If I have the right doc entry Jim refers to, it returns,

Get a unique identifier for the auth session value. returns a string

I learned from SO that Auth::getDefaultDriver() does return web as a string. But I need to find the guard in use in the admin app.

If I use $this->guard() I get an array with the guard (see above) to be used during authentication as per the comments on L 166 of AthenticatesUsers.php

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@jimmck

I bought Matt Stauffers book a few weeks ago which is also very helpful.

I would really like some advice on using the API docs. In my efforts to solve this multi-authentication problem I have indeed been looking into the source code for Laravel, specifically the trait AuthenticatesUsers.php and others.

I see funky methods which are not featured in the user docs. So I try to find them in the API docs. BUT, there must be a secret to quickly finding stuff in the API, as I have found that you can dig around looking for 10 minutes at a time before you might find the method. What is the secrete, or is this just an experience thing ?

Thanks !!

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@jimmck

Current specs of current system is:

Linux Mint 18.1 ( this uses Ubuntu 16.04 LTS at it's core) PHP 7.0 ( I want to upgrade again to 7.2) Apache 2.4.18 MySQL 5.7.18 Storm 2017 Laravel 5.4

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@Snapey @jimmck

Many Thanks for that Snapey !

Tried your statement, but I got an error from your statement:

Parse error: syntax error, unexpected -> (T_OBJECT_OPERATOR)

So I tried it like this:

dd(Auth::guard()->getName());

And it does not return the admin guard. In fact of you do a dd() on it you get:

"login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d"

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@jimmck Thanks jim. I did have Storm debugger working, then, I upgraded my Linux version, which requires a 100% OS reinstall and rebuild of the PC. I also upgraded Storm as well, and between the two upgrades I have not yet reinstalled the debugger. Top of my list, once I get this darned thing fixed - promise !

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

Multi Authentication in Laravel ( a pain)

The story so far: Thanks to jfadich on SO I have got as far as trying getDefaultDriver method which does indeed return the default driver web. However, I need to get the driver in use. This means when I log out from the admin site, I need to be able to test which driver is in use, and if admin, return the admin login page. I will always get the default ie 'web', even if I am using an admin guard? So, jfadich has asked to see my guard set up:

  'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    'admin'=>[
        'guard' => 'admin',
        'passwords' => 'admins',
     ],




  'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],

        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
    ],




  'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],


         'admins' => [
            'driver' => 'eloquent',
            'model' => App\Models\Admin::class,
        ],

      
    ],

vincej left a reply on Can't Make Auth::guard Work As Expected. • 3 weeks ago

@jimmck Heah Jim, thanks for coming back.

We had a national internet outage yesterday afternoon, just as I was about to respond to you :(

Looking at the Laravel api, Looking the AuthenticatesUsers.php line 170, there is a function which does get the guard. Once I have the guard I can test for it.

 protected function guard()
    {
        return Auth::guard();
    }

If I call that function, and do dd($this->guard()); I get an array in a weird (json?) format which does contain the guard name.

SessionGuard {#395 ▼
  #name: "web"
  #lastAttempted: null
  #viaRemember: false
  #session: Store {#379 ▶}
  #cookie: CookieJar {#378 ▶}
  #request: Request {#38 ▶}
  #events: Dispatcher {#23 ▼
    #container: Application {#2}
    #listeners: array:3 [▶]
    #wildcards: array:1 [▶]
    #queueResolver: Closure {#24 ▶}
  }
  #loggedOut: false
  #recallAttempted: false
  #user: User {#404 ▶}
  #provider: EloquentUserProvider {#389 ▶}
}

Question How do I extract the name out of the object/array? Many thanks !

27th April, 2017

vincej left a reply on Can't Make Auth::guard Work As Expected. • 4 weeks ago

any ideas anyone ?

26th April, 2017

vincej started a new conversation How Does Auth::guard Work ? • 4 weeks ago

I am using Auth::guard to check which guard is being used during the logout. If it is an admin guard, then I wish to redirect to the admin login, otherwise it goes to a users login.

My assumption is that Auth::guard('admin') checks to see if the guard is indeed of type admin. If so it progresses with the if statement.

However, it is not working the way I expect. I check my guard with a dd(Auth::guard()) and it is definitively a web guard. BUT regardless, the Auth::guard('admin') is still letting it through.

What am I doing wrong? Is my assumption re Auth::guard wrong? Many Thanks !

  if (Auth::guard('admin') ) {

            $this->guard()->logout();

            $request->session()->flush();

            $request->session()->regenerate();  /*dd('line 85');*/

            return redirect('admin-login');
        }
        else {

            $this->guard()->logout();

            $request->session()->flush();

            $request->session()->regenerate();  /* dd('line 96');*/

            return redirect('/login');
        }


11th April, 2017

vincej left a reply on I'm Starting To Hate Laravel • 1 month ago

Having come from a CodeIgniter background I've been working with Laravel for 2 years now and I still consider myself a beginner. Comparison to CI Laravel is pretty dense however, I would never go back.

The only think that frustrates me is how I look into the Laravel source code and I see loads of great chainable functions many which are not in the docs.

So I hunt through the API hoping to find some explanations on how I might be able to use them as well, thus raising my own game. Often I find it a bit of a mystery how to use these functions. I would love better docs or least some advice on how better to search and find stuff in the API.

7th April, 2017

vincej left a reply on Apache Will Not Serve Files Past The "Welcome" Screen • 1 month ago

Many Thanks for all your contributions !! Without you guys I would have given up a long time ago.

When you are using Linux ( Now, I use Mint 18.1 ) you have to completely rebuild your machine when you make an upgrade. So, I went from Mint 17 > 18.1, which in Ubuntu terms is 14.4 > 16.x

@oaj gets the booby prize. I don't look at Apache often and so I had total missed the fact that they had changed their directory options. Thanks !!

6th April, 2017

vincej started a new conversation Apache Will Not Serve Files Past The "Welcome" Screen • 1 month ago

I had to rebuild my Linux machine with a clean install of Linux, Apache etc and Laravel 5.4

Apache serves up the welcome screen but will not deliver anything else. Not the home screen, Login, Register , nothing. All I get this the error saying it can not find the URL. Home screen is not generated by the make:auth command.

The requested URL /home was not found on this server. Apache/2.4.18 (Ubuntu) Server at auburntree Port 80

I have checked everything over a hundred times: the routes, virtual hosts, hosts file, permissions I set to 777, storage folder open. The owner is set to myself, and the group is set to www-data. I have also tried setting the group to myself as well. I have restarted and reloaded a hundred times. I have enabled the site. My root folder is set to public. I have swapped the htaccess file out for the alternative as per the docs and then returned the original. Cleared the cache on the server as well as in the browser several times.

I also created a little test site with a single html page and that was served up ok.

I am obviously missing something very stupid. The fact that it will serve the welcome page tell me the site is loading,

Has anyone else had this problem? What am I missing ?

Many thanks !

31st March, 2017

vincej left a reply on Getting Login Error Since Upgrade To 5.4 • 1 month ago

thank you again. I guess I am getting hung up on the idea that isEnquire is part of an eloquent accessor needs to be a column in the DB. Clearly, the way you describe and I understand it, is that does not.

I understand the thrust of what you are laying out, but will need to study some more before I understand how getisEnquireAttributecan function as an accessor and yet isEnquire is not n the DB.

vincej left a reply on Getting Login Error Since Upgrade To 5.4 • 1 month ago

@Snapey

Thanks for all your help !

I am sure that what I am doing is wrong. Part of my confusion is that I am looking at your advice, then looking at Matt Stauffers Book, and getting totally confused by the isEnquirer of your accessor. Here is a small snippet from his book presenting how he explains how an accessor works:

https://drive.google.com/open?id=0B5elaUk7GlRoTS1teVUyXzA5MTQ

This is why I am putting getUserGroupAttribute into the accessor.

It appears to get the value when I am in the model but then, it fails with all kind sof errors, when inside the redirectTo() method.

Sure, I always like to do things correctly, but I don't want to put you out anymore. You have you own life. So for the mean time, I have temporarily gone back to my kludgey solution.

Anyway, I have a more pressing problem than this: once the user is authenticated how to change the guard from 'auth:user' to 'auth:admin', so that users can not get into the admin pages. Laravel appears to be quite weak, when it comes to Multi authentication, and multi password resets. Cheers !

30th March, 2017

vincej left a reply on Getting Login Error Since Upgrade To 5.4 • 1 month ago

@Snapey Thanks for your rapid reply.

I follow your thinking, however, when I transpose your code into my app I am getting an error:


    public function getUserGroupAttribute(){

        return $this->user_group == 1;

    }

Undefined property: App\Models\User::$user_group

note, user_group is the name of the column.

vincej left a reply on Getting Login Error Since Upgrade To 5.4 • 1 month ago

@Snapey

Hi Snapey, I have been looking at accessors etc having never used them before, and I have gotten as far as getting the value back out of the DB like this:

From my model (user_group is the db column name)

    public function getUserGroupAttribute($value){
        return ($value);
    }

Login Controller

    protected function redirectTo()
    {
                $user = User::find(19);
                $usergroup = $user->user_group;
          
             dd($usergroup);  //THIS WORKS

    }

And sure enough I am getting the correct user group out.

Question I do not understand how to make use of this syntax inside my model. Can you please help me understand how this works? I have got Matt Stauffers book, but he says nothing about this, and I can not find anying on Google far.

->isEnquirer should be referencing a function called "isEnquirer" ... but how that that fit with the accessor method, getUserGroupAttribute

 if(Auth::user()->isEnquirer) {
            return '/dashboard';

Sorry, I'm a bit lost here.

Many Thanks !

13th March, 2017

vincej left a reply on Why, Since 5.4 Upgrade Form::Open(['action' .... ]); No Longer Works • 2 months ago

yeah, I was using 5.4 then I though I'd give 5.4.1 a try to no effect.

I can get around it with a url, but it is a pain when something does not work as expected.

Many thanks !

vincej left a reply on Why, Since 5.4 Upgrade Form::Open(['action' .... ]); No Longer Works • 2 months ago

@jlrdw Thanks for that. I have 5.4.1 specified already in my composer file, without any errors on update.

vincej started a new conversation Why, Since 5.4 Upgrade Form::Open(['action' .... ]); No Longer Works • 2 months ago

I have googled this to death as well as looking through the upgrade guides. I can not see the reason why this is happening. Any ideas are welcome.

Under 5.1 my blade From Open actions all worked, now, no more. My expectation is that using the action method I do not need to define a specific route. My 'action' will generate the specified route to my controller function. I keep getting the error

ErrorException in UrlGenerator.php line 337:
Action App\Http\Controllers\ContractorPortal\[email protected]_update not defined. 

(View: /var/www/auburntree/resources/views/contractor_portal/change_password.blade.php)

BUT

  1. The controller is defined.
  2. The controller is Namespaced.
  3. The is no route defined in the web.php
 {!! Form::open(['action' => 'ContractorPortal\[email protected]_update', ['id'=>$id] ]) !!}

*Controller: *

 public function password_update(Request $request,$id){

        $user = User::find($id);
        $new_password = $request->new_password;
        $user->password = $new_password;
        $user->save();

        flash::success('Password has been updated');
        return view('portal/contractor_account');
    }

2nd March, 2017

vincej left a reply on Upgrading To 5.4: Why Does Laravel Invent It's Own Urls ?? !! • 2 months ago

throughout my app I use resourceful routing. The redirect:

 return 'portal/contractor_account';

opens a view containing the following route:

includes an open::form{{ ['route' =>'contractor_account.update']}}

This is where the "Update" was coming from.

Notice there is no model specified. L5.1 did not seem to worry about this. My app worked fine as within the 'update' controller I grabbed the model id using a $request->id

However, within L5.4 and Collective 5.4 things are a bit more strict, as @Snapey has pointed out to me in another question I posted this pm.

So as part of the upgrade, I need to go through my app and update all the routes.

I've learned a big lesson about Laravel: if you do not have to, do not stay on LTS issues. Trying to upgrade 3 versions in 1 hit is just too painful. Better to keep up.

As always MANY THANKS !

vincej left a reply on Upgrading To 5.4: Why Does Laravel Invent It's Own Urls ?? !! • 2 months ago

Many thanks to all. Whilst no specific answer gave me the specific solution, one way or another all of your contributions helped me identify the problem and fix it.

Thanks !

vincej started a new conversation L5.4 Upgrade From 5.1 : Why Does Collective Not Work ? • 2 months ago

I've just upgraded fro 5.1 to 5.4. Everything worked in 5.1, however, now I find that when I use Resourcefull routing, collective does not work. My service providers and aliases are up to date. I have upgraded by collective to 5.4 and done a composer update:

{!! Form::open(array( 'route'=>'crews.destroy', 'method'=>'delete')) !!}

Route:

Route::resource('crews','CrewsController');

However, if I change my route to a get, and a url in the view then it all works again. I don't want to have to upgrade my whole app as a result.

What gives ? Thanks !!

1st March, 2017

vincej left a reply on Upgrading To 5.4: Why Does Laravel Invent It's Own Urls ?? !! • 2 months ago

@cviv Thanks for that. Nope, the route really is defined there with a "get".

28th February, 2017

vincej left a reply on Upgrading To 5.4: Why Does Laravel Invent It's Own Urls ?? !! • 2 months ago

@jimmck Thanks for that Jim. Any ideas why L5.4 invents a url called "portal.contractor_account.update". The update part does not exist. I am guessing that it has something to do with automatic resource routeing.

I tried forcing a route with a "get" but L5.4 just ignored it.

Trying to upgrade from 5.1 to 5.4 though composer was hopeless, so I installed a wholly fresh 5.4 and loaded it with my app. Is it possible that there is some kind of application caching going on? I did a artisan clear:routes to no avail.

5.4 seems to have a mind of it's own. So far it has been a real pain.

Thanks for your help.

vincej left a reply on Getting Login Error Since Upgrade To 5.4 • 2 months ago

Good point, thanks ! However, since your reply I have a new problem, which I have written up under a new question.

5.4 is creating it's own url's https://laracasts.com/discuss/channels/laravel/upgrading-to-54-why-does-laravel-invent-its-own-urls

I hate 5.4. Nothing works the way you expect it.. Everything under 5.1 was straight forward and worked. Taylor is getting too clever for his own good. He abstracts everything and as a user, I have no idea why things are doing what they are going and where things are. Ugh.

vincej started a new conversation Upgrading To 5.4: Why Does Laravel Invent It's Own Urls ?? !! • 2 months ago

Everything worked great in 5.1 - now I don't understand what is going on.

Within the Logincontroller I have a function:


 protected function redirectTo()
    {
        $id=Auth::id();
        $user = User::find($id);
        if($user->user_group == '0') {
            return '/dashboard';
        }
       return 'portal/contractor_account';

    }

If I am returning to the '/dashboard' it decides that it will go to 'Home'.

Crazier still, if I have a user which needs to return to 'portal/contractor_account' Laravel decides that it will invent it's own URL :

Route [portal.contractor_account.update] not defined.

NO Where have I specified an "update" route ! Why is 5.4 taking control over my app like it's Microsoft ?

Second question - where in the heck are all the routes stored from Route::Auth(); ??

Edit Your Profile
Update

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