neilherbertuk

ICT Systems Development Engineer at Keele University

Experience

20,840

11 Best Reply Awards

  • Member Since 2 Years Ago
  • 199 Lessons Completed
  • 0 Favorites

19th September, 2017

neilherbertuk left a reply on Force The User To Validate The Mail To Navigate In The App • 3 days ago

Hi SYLVERT,

This can be done with middleware, checkout the official docs here - https://laravel.com/docs/middleware

Neil

18th September, 2017

neilherbertuk left a reply on Problem With Restricting Access To A Particular Page • 3 days ago

Check your Laravel.log and http server error log file for exact details of why you are getting the 500 error.

16th September, 2017

neilherbertuk left a reply on File Can Not Be Submitted In Form • 5 days ago

Pretty sure you need to add enctype="multipart/form-data" to your form tag

 <form action="/profile" method="POST" enctype="multipart/form-data">
        {{ csrf_field() }}
        <input type="text" name="username">   
        <input type="file" name="photo">                           
        <button type="submit">submit</button>                           
    </form>                            

Neil

neilherbertuk left a reply on Pulling More Than One Value In Query Builder • 5 days ago

Hi Patwan,

I'm not sure if I'm understanding what you want to achieve. The price field should be available in blade under {{ $item->price }}? Can you explain in more detail what you've tried and what isn't working rather than what you want to do?

Neil

15th September, 2017

neilherbertuk left a reply on Append Pivot Data To Model (?) • 6 days ago

Hi Eminos,

Not sure you are using Pivot or Many to Many relationships in the right way, it's hard to tell with what code you've given. Check out https://laravel.com/docs/5.5/eloquent-relationships#many-to-many

This is how I would do this

Attribute.php model

public function productCategories()
{
  return $this->belongsToMany('App\ProductCatagory');
}

ProductCategory.php model

public function attributes()
{
  return $this->belongsToMany('App\Attribute');
}

You would now have a new table on your database named Attribute_ProductCatagory with an id field for both tables. Attribute_id & ProductCategory_id.

You would then do something that's the reverse of what you are currently using to get attributes.

  $product = ProductCategory::where(...what ever logic you want here..)->with('attributes')->first();

Attributes would then be available via $product->attributes

To attach an attribute, you can use the attach method.

  $product->attributes()->attach('attribute id here');

You would do the exact same with the attribute to attach a product category.

Neil

14th September, 2017

neilherbertuk left a reply on Socialize 500 Error • 1 week ago

FRANCESCO331 please edit your post above, it looks like you've included an API key in your log entry. Can you confirm what package you are using? Are you using Laravel's Socialite or nanuly/socialize?

Neil

neilherbertuk left a reply on Socialize 500 Error • 1 week ago

Hi FRANCESCO331,

It would be helpful if you could provide more detail to allow someone to be able to answer your question. Please check out Laracasts Posting Guidelines which details what makes a good post and the sort of information needed to be able to help answer you.

What have you done so far? Have you checked out the Laravel.log file and your web servers error logs for the error details?

Neil

neilherbertuk left a reply on Nginx | Can Only Access Some Routes But Not All • 1 week ago

Hi KAZUTO,

It would be helpful if you could provide more detail to allow someone to be able to answer your question. Please check out Laracasts Posting Guidelines which details what makes a good post and the sort of information needed to be able to help answer you.

Please can you post your routes file, the server os and the os of your local environment, what version of nginx, what version of PHP and what version of Laravel you are using.

Neil

12th September, 2017

neilherbertuk left a reply on How Can I Build Modular Architecture In Laravel ? • 1 week ago

Hi ONDERSAHIN,

I've been working on a package that does exactly this. It's still under development but it does the job. https://packagist.org/packages/neilherbertuk/laravel-modules - I've been working on this for a number of months and was getting fed up with copying it to new projects so thought I would release it, even if it's only to make my life easier! There are a few tutorials and packages out there that do this, but I hope to include lots of extra features such as artisan commands to help quickly create a new module. So far it can create routes and controllers. Everything else currently has to be manually made.

Even if you don't use my package, take a look at the ModuleServiceProvider.php file as that is what loads everything. On boot it looks at each folder within app/Modules and looks through it to see what it needs to load.

Neil

neilherbertuk left a reply on Penetration Test - Laravel_session Cookie Termination • 1 week ago

Hi ucreate.it,

Potential security vulnerabilities really should not be discussed in the public domain in the first instance.

As per Laravel's Documentation

If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed.

Neil

11th September, 2017

neilherbertuk left a reply on ACL Abilities Not Being Define In Production Environment • 1 week ago

Glad to got it working, did it start working directly after the server restart? Might be worth double checking if opcache is enabled as this sounds like it is! (Check your phpinfo() to see if it is)

neilherbertuk left a reply on Undefined Property, Trying To Get Property Of Non Object, Creating Default Object From Empty Values • 1 week ago

Hi Pafait,

It would be helpful if you could provide more detail to allow someone to be able to answer your question. Please check out Laracasts Posting Guidelines which details what makes a good post and the sort of information needed to be able to help answer you.

Can you provide code for where you are seeing this? This error is usually when you are trying to access a collection as an array or the other way round, or when a collection or an entity of a collection you are trying to use just isn't set.

Neil

neilherbertuk left a reply on Logout Locked Users • 1 week ago

The only issue with global Middleware would be to make sure you account for a user not being logged in. Depending on the logic you use, you may get errors from null or non-existent variables.

neilherbertuk left a reply on Logout Locked Users • 1 week ago

Hi wizjo,

Not sure if the field "active" describes what you are trying to do accurately enough, perhaps it would be worth changing this to the word "locked"?

You should probably put this kind of logic into Middleware. A quick search of the boards shows a similar post here which answers your question:

Create a new middleware

    $php artisan make:middleware CheckIsLocked

Add it to your $routeMiddleware within app\Http\Kernel.php

    'isLocked' => \App\Http\Middleware\CheckIsLocked::class,

Edit the app\Http\Middleware\CheckIsLocked.php Middleware.

You can access the logged in user from the $request variable: $request->user()->active

Then add the isLocked Middleware to the appropriate routes.

Neil

neilherbertuk left a reply on ACL Abilities Not Being Define In Production Environment • 1 week ago

Have you got opcache enabled on your production server?

Neil

10th September, 2017

neilherbertuk left a reply on Digital Signage • 1 week ago

Hi JOECODE,

There already are some great open source digital signage packages out there. Not sure if it's wise to reinvent the wheel for such a complex system. If you are serious about writing something in Laravel, check out xibo. It's a php based (doesn't use Laravel) digital signage platform that's open source. Might be a good place to get some ideas.

Neil

neilherbertuk left a reply on I Am Using Server Site Data Table Package In Laravel 5.3 I Have Got Json Response How I Can Render In Html Please Help Me. • 1 week ago

Hi LARA123,

It would be helpful if you could provide more detail to allow someone to be able to answer your question. Please check out Laracasts Posting Guidelines which details what makes a good post and the sort of information needed to be able to help.

Things like, what package you are using (provide links), the code being used to generate what you've posted, more info to how you want to consume that data?

A basic assumption that you want to use the json as an array or collection you can use the built in PHP function [json_decode](http://php.net/manual/en/function.json-decode.php) to convert it to an array and then the laravel function ```collect` to turn it into a collection. You can the consume this data as you normally would in Laravel.

Neil

neilherbertuk left a reply on Using Redis As Main Data Source • 1 week ago

It would completely depend on use case and what your internal requirements are. What sort of data are you using, how often it would be accessed.

If your need for Redis is about hitting below a certain time to respond to the user, then yes, cache everything. However, it would be pointless to cache data that doesn't get used very often, as you would be dedicating extra resources to store it both in MySQL and again in cache.

Problem is as your data grows, so will your caching infrastructure. Which will lead to potentially unnecessary cost of servers, the more resources you throw at Redis, obviously the higher the operating costs become. If you want to hit sub certain times across multiple regions you'll also need to consider Redis clustering and routing to the nearest data centres etc.

I don't personally prefer either way. It really does depend on use. Such as multi-tennant applications, it makes sense to cache data that will be accessed globally such as config or site specific branding or such forever, but caching data that a single user might access once a day, or only a few times a week doesn't make much sense to me. In that case, cache for a limited amount of time, or don't bother at all.

Neil

neilherbertuk left a reply on Ajax Call Not Hitting Success Event, Error Event Always Fired • 1 week ago

Hi OLOTUDAMMY,

Before posting any further questions please take a look at the following post - Laracasts Posting Guidelines - this will help you provide enough information to get an answer to your question.

First thing, can you please give us some more context? Can you post the html and PHP that supports this function? Where have you taken the code you've pasted above from, a view? or from the rendered page? As it's showing a blade directive it would be useful to see the rendered script so we can see what URL you are trying to call?

What have you tried so far? Have you used your browses debug tools (usually F12) to see what's going on? Have you tried to include code that shows you what response the Ajax call is getting?

Neil

neilherbertuk left a reply on Which One I Should Return First Json Or RedirectPath??? • 1 week ago

Hi TANGGUH,

Can you explain in more detail what you are trying to achieve? Under what circumstances does your app require you to return json? Are you using Ajax calls? Are you exposing an API?

As soon as a return statement is called, the method terminates. So your last line never fires. If you don't need the json response at all, simply remove it

Neil

neilherbertuk left a reply on Multiple Controller For Single View • 1 week ago

Hi ZETTZ,

This can be achieved using a View Composer and a service provider.

Within a service provider, this could be the default AppServiceProvider but should probably be in it's own Service Provider.

There are a couple of ways of doing this, here is a basic example of using a closure to return something to your views. Within the boot method add:

View::composer('*', function ($view) {
  // Logic here
    $view->with('config', 'This is the config value');
});

The * acts as a wildcard, you could put a single view here, or an array list of views you want to make this available too. Using the wildcard, within your views would be a globally available variable named $config which will return the string value 'This is the config value'.

You can also use the route style syntax and include a view composer class to separate the logic into its own place.


// Using class based composers...
        View::composer(
            '*', 'App\Http\ViewComposers\ConfigComposer'
        );

You would then create a view composer class and use the same $view->with logic to add your config.

Neil

Some resources:

9th September, 2017

neilherbertuk left a reply on Using Redis As Main Data Source • 1 week ago

That's not something I use it for, but there is no reason why you can't. However, it would make your writing mechanisms longer as you would need to regenerate your entire HTML to include the change, otherwise the end user wouldn't see it. Laravel has its own caching system which works with Redis out of the box - https://laravel.com/docs/5.5/cache - though you do need to pull in another package to enable it.

I might add that Redis might be overkill for your needs. Oh and btw the workflow I mentioned is how Facebook works, though they use memcached instead of Redis.

Neil

neilherbertuk left a reply on Pull Models From Relationship Data • 1 week ago

Hi LMARTINS,

You need to add a query scope to your purchases model.

https://laravel.com/docs/5.5/eloquent#query-scopes

You can do this as an anonymous global scope, something like this should do it. Add this to your purchases model (not tested code)

 protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('product', function (Builder $builder) {
            $builder->with('Product');//Must have a relation on your product and purchases models to each other
        });
    }

Neil

neilherbertuk left a reply on How To Display First, Middle And Last As Full Name. • 1 week ago

Hi SMEHSAN,

There are several ways you could tackle this.

You could add an additional field to your table for full name, and concatenate the 3 names into that column when you store data. Not the best solution as it would duplicate data and would have to be updated if the name gets changed.

You could add an accessor to your student model something like

public function getFullnameAttribute(){
  return $this->fname . ' '. $this->mname .' '. $this->lname;
}

Within your blade view you would then call {{ $student->fullname }}

You could also add a newquery scope to your model to automatically combine the 3 into a new column. I'm not going to cover that as it is overkill.

The easiest way would be simply to echo out each field directly in your blade view

{{ $student->fname }} {{ $student->mname }} {{ $student->lname }}

Neil

neilherbertuk left a reply on Using Redis As Main Data Source • 1 week ago

Hi KONSTANTINRACHEV,

There is a lot to think about if you plan on using Redis. I'm no expert but I will try and answer you to the best of my knowledge.

First thing first, Redis is an in memory key value store. It's not capable of being queried in the same way a MySQL database can be. So keeping this in mind, you need to know the key of what ever you want to retrieve. A lot of thought will need to be put into your naming convention because of this.

Some gotchas or caveats, as it's in memory, the amount of memory available on the server will limit the amount of data you can store. Out of the box, it also doesn't write anything to disk. You can enable snapshots which will write a copy of what's stored to disk on a time schedule or when a certain number of changes have been made. Without this, if your server reboots, you will lose everything in memory. With it, it will take a while for your Redis server to recover when it restarts. You will lose anything that was changed since the last snapshot.

Redis is generally used for caching and not a standalone storage service. My use of Redis uses MySQL as the main storage engine and Redis for reading. So the workflow would be:

Write to MySQL followed by writing to Redis. So anything that gets updated in MySQL also gets updated in Redis. From a reading point of view everything is read from Redis first, if it isn't there I will read it from MySQL and write it to Redis. With this method it takes less time to recover if your Redis server goes down. Reads will be a bit slower to start with, but at least the data will be available straight away.

Redis is a fantastic layer to add for caching, a typical MySQL query might take 200ms, pulling the same data from Redis will take 10-20ms, so it is great for speeding sites up.

Hopefully this gives you some idea of how to get around failures. If you have any further questions, I will try to answer them.

Neil

26th June, 2017

neilherbertuk left a reply on My Credit Card Showing Insufficient Funds • 2 months ago

Hi NAGAVINOD424,

I would suggest you use the following link to get in touch with Jeffery - https://laracasts.com/contact

Something perhaps worth checking? Does your issuing bank allow you to make payments in forgien currency? If so it may also be worth checking what fees they charge as most banks charge a percentage of the transaction plus an admin fee, you will need to account for that while making payment. Your best bet would be to get in touch with your bank and check why they declined the transaction, as they are likely able to tell you more than Jeffery can.

Neil

23rd June, 2017

neilherbertuk left a reply on Failed To Load Resource: The Server Responded With A Status Of 500 (Internal Server Error) • 2 months ago

Take a look at your Laravel log file, you'll find it at /storage/logs/laravel.log

Within this you'll see a more detailed error log of what's causing the issue.

Neil

20th June, 2017

neilherbertuk left a reply on How Do You Push A Script Onto A Stack Only If It Doesn't Exist Yet? • 3 months ago

Hi Tag,

This is probably one of the most annoying features of the @push and @stack blade features. You can't easily check if something already exists.

I usually resort to using PHP for this purpose, it is a slightly dirty way of working around the issue, but it does work. I'd be keen to know if anyone else has come up with a better solution.

@push('scripts')
  @if(!$scriptAlreadyIncluded)
    <script src="file.js"></script>
    @php 
      $scriptAlreadyIncluded = true;
    @endphp
  @endif 
@endpush

Neil

16th June, 2017

neilherbertuk left a reply on Variable In Url() Helper • 3 months ago

You should be able to use concatenation to do this, use dots instead of commas.

{{ url('/group/'. $var .'/profiles') }}

Or this should work with double quotes

{{ url("/group/$var/profiles") }}

neilherbertuk left a reply on Provision Server And Test On Subdomain On Different IP • 3 months ago

This is something you can do with your DNS, you'll need to create a cname or A record, pointing it at the server you want to serve from.

A cname can be pointed at another URL, or an a record can be pointed at an IP address.

15th June, 2017

neilherbertuk left a reply on Doubt With Laravel Deploy, Git And .gitignore Files • 3 months ago

Hi MANEL69,

Your . gitignore file contains what it does for good reason. Firstly it keeps your project small so it's quick to deploy. Your git repo is set using this to not include your vendor folder, as everything in your vendor folder is already on a git repo, it does not make sense to duplicate code, it also allows you to make sure the packages you've pulled in are up to date (security fixes etc).

Secondly, for security it does not include your .env file, this is to prevent passwords getting stored in version control. As you have access to the server you are deploying on you can copy your .env file, or create a production version manually, once it's in place it won't get overwritten as git will not touch it.

Your vendor folder is easy to sort, you will need to ensure that composer is installed on the server you are deploying to, simply run the following from the root of your project.

composer install

This will install all of the missing dependencies within your vendor folder.

Neil

7th June, 2017

neilherbertuk left a reply on How To Work With Fixed State/status/type Fields • 3 months ago

Hare coding is never a good idea, however you could use an enum column on your database.

https://laravel.com/docs/5.4/migrations

$table->enum('choices', ['foo', 'bar']);    ENUM equivalent for the database.

This would limit the possible values to anything within the array provided, so in the example above, the column named 'choices' could only ever be too or bar. You could then select the rows you are after by simply adding a where to your query.

Neil

neilherbertuk left a reply on 403 Forbidden On New Projects • 3 months ago

Routing is done from the root of the domain, so anything after the domain is used as your route path. So even if your project is sat inside a folder named "home" and the URL is chill-pill.com/home, remove the domain and that's the route needed. To make it easier you can create a routing group with a prefix of home so you don't have to change too much.

https://laravel.com/docs/5.4/routing#route-group-prefixes

Route::group(['prefix' => 'home'], function () {
    Route::get('users', function ()    {
        // Matches The "/home/users" URL
    });
});

neilherbertuk left a reply on Blade Check If Variable Is In Array • 3 months ago

Hi Toneee,

You can use regular php within your blade if statements, such as

If you are looking for a keyname

@if(array_key_exists('keyname', $array_to_search))
    {{ $array_to_search['keyname'] }}
@endif 

http://php.net/manual/en/function.array-key-exists.php

Or searching for a particular value

@if(in_array('value', $array_to_search))
    Output String
@endif

http://php.net/manual/en/function.in-array.php

Neil

neilherbertuk left a reply on 403 Forbidden On New Projects • 3 months ago

Hi Charlie,

First thing to consider, it is generally considered bad practise to house your Laravel project within a publicly accessible folder, you will need to be extremely careful of people being able to download your .env file.

First off, what sort of access do you have to the server? Also just want to make sure you are using Apache or nginx? .htaccess files only work with apache.

Probably not the best way round, but I have achieved this type of setup by using aliases within the Apache config. Rather than housing everything inside your /var/www/html folder, you put your projects within the /var/www folder and use aliases to point a domains subfolder at the public folder within say /var/www/home/public, this keeps everything out of public access but happily serves your application.

Can't give you an example ATM but might be a good starting point.

Neil

neilherbertuk left a reply on Laravel 5.4 Mistake In Make:listener, IlluminateAuthEventsRegistered • 3 months ago

Unfortunately​, the Laracast Discussion Boards are nothing officially to do with Laravel. All bug reports should be posted to the issues board on the official Laravel Framework Github repo - https://github.com/laravel/framework/issues

6th June, 2017

neilherbertuk left a reply on Middleware • 3 months ago

Hi ABUBAKAR,

What are you trying to achieve? It sounds to me that your employees must not have access to the admin panel? If so, this sounds to me like you are after ACL or Roles within your application. This can be done using (Gates)[https://laravel.com/docs/authorization]

Jeffrey has some videos on this - https://laracasts.com/search?q=Acl

Hope this helps.

25th May, 2017

neilherbertuk left a reply on I Am Getting "This Page Isn’t Working. Localhost Is Currently Unable To Handle This Request. HTTP ERROR 500" • 3 months ago

500 errors won't appear in your laravel.log file, you will need to check the http error logs for your server.

neilherbertuk left a reply on I Am Getting "This Page Isn’t Working. Localhost Is Currently Unable To Handle This Request. HTTP ERROR 500" • 3 months ago

Hi rameshreddy2294,

Are you getting this error with every request? Check your http error logs as that will tell you whats causing the issue.

If it's not making much sense, make sure the log doesn't contain any passwords but share it with me via https://paste.laravel.io/

Neil

neilherbertuk left a reply on Laravel 5.4 Not Working On Linux Shared Hosting • 3 months ago

Hi VISHAL,

Laravel can be difficult to get working with Shared Hosting. First port of call would be to check your admin panel to see if they provide you with access to any error logs. Something the logs are available from FTP, sometimes from an admin panel. Your error logs will tell you more detail to why your application isn't working.

I think the most common issues for 500 errors tend to be permissions related or missing php extensions. However there are a lot of things that could be stopping it.

Make sure your storage and bootstrap/cache folders have the correct permissions. Most FTP clients allow you to change your permissions through chmod.

If you find your error logs, make sure they don't include any passwords and paste it here.

Neil

24th May, 2017

neilherbertuk left a reply on How To Run The Cloned Laravel Project From Github To Windows Xampp? • 3 months ago

If you are only using windows for a test / Dev environment I'd suggest you look at Laragon instead of xampp. It's designed for use with Laravel projects.

Once installed you can open cmder (the terminal link from the Laragon GUI).

git clone http://... NameOfFolderToPutItIn

cd into the folder you specified above

composer install

If all has gone well, hit start all, you should now be able to visit http://NameOfFolderToPutItIn.dev/ (replace that with the folder name you used in the git clone command) on the machine you have it installed on.

22nd May, 2017

neilherbertuk left a reply on Laravel - Append A Trailing Slash In Every Routes • 3 months ago

After taking a look into this further, it appears to not be possible with the behavior you would like.

So the default behavior when using Laravel on Apache2 is as follows.

Default Behaviour

When you include a slash, unless it's a folder the trailing slash gets removed.

The following rules within .htaccess causes anything with a trailing slash that is not a folder to be given a 301 Moved Permanently response. This will cause your browser to redirect to the new url without a trailing slash.

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

If you make any changes to this mod_rewrite rule, you will need to make sure you clear your browsers cache, otherwise the 301 will still be known to your browser and will redirect you anyway.

I've removed this rule from .htaccess, cleared my browser cache and performed the same http request.

New Behaviour

As you can see the url no longer redirects / removes the trailing slash.

Unfortunately, it appears that Laravel can't differentiate between routes with a trailing slash and without. I suspect this is because / is stripped by Laravel as a separator to find the resource / route thats required and any parameters / options / variables within the url.

Route::get('/test/', function(){
    return "Trailing Slash";
});

Route::get('/test', function(){
    return "No Trailing Slash";
});

When this is included in the web.php routes file, I only get the No Trailing Slash response.

The best I can suggest, if you are desperate to have the trailing slash present, is to reverse the current rule, change the rewrite rule so it adds a trailing slash if not present. The docs for mod_rewrite should be the best place to start.

neilherbertuk left a reply on Laravel - Append A Trailing Slash In Every Routes • 4 months ago

Not the most helpful of replies! What are you using to serve your application? What have you tried? What isn't working?

My reply was meant to be a starting point, a springboard to point you in the right direction. If you are using Apache, the behaviour you are after isn't possible with Laravel out of the box. You will need to modify your mod_rewrite rules to prevent it from removing the trailing slash. It might be worth swapping the rule around so it redirects from non trailing slash URLs to include a slash. Unfortunately, mod_rewrite rules can be hard to get right so you should probably take a look at the docs http://httpd.apache.org/docs/current/mod/mod_rewrite.html

21st May, 2017

neilherbertuk left a reply on Laravel - Append A Trailing Slash In Every Routes • 4 months ago

Hi baqirmemon,

What are you using to serve your application? If you are using apache, the .htaccess file that ships with Laravel actually strips the trailing slash from urls.

# Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

You could try to remove this, however I have no idea if it would cause you any other issues as I've not tried it myself. You may want to look into apache mod_rewrite which handles all of this behavior. You may be able to add the behavior you are after such as adding a trailing slash, however you will need to include rules that allow files such as images and assets from being excluded from any rules you add, otherwise the http server may think you are trying to access a folder that does not exist.

If you are using nginx there will be a similar rewrite rule that does the same.

Neil

neilherbertuk left a reply on Seed A Column In The Middle Of Register An User • 4 months ago

Snapey has a point, as you already have the data stored, it would make sense to de-duplicate, and dealing with keeping the record up to date would be a headache in the long run!

neilherbertuk left a reply on Seed A Column In The Middle Of Register An User • 4 months ago

Hi brunofrancisco,

Using DB::getPdo()->lastInsertId(); is probably not a good idea, however rarely it may occur, if you had two users registering at the same time. You could hit issues with the wrong user being updated. As you already know the details of the user from the form they've filled out, you could do a select, where the user details match those given on the form.

The code you've provided, also doesn't specify which user you are updating. You would need to include a where clause to specify which user row you were updating. Are you set on using the DB facade or are you happy to use Eloquent?

 DB::table('users')->update(['userProfile' => $result])->where('id', $userAux->id);

A far easier option would be to make use of Eloquent Models, which is the default way of registering a user. On your RegisterController.php you have a Create method which is called when you submit the registration form. You can within this method put any other code needed to create the user. As I said, by default this uses the User Eloquent model.

The default is

    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }

Assuming you are receiving the firstname and lastname from your form. You could change this logic to include your userProfile field

    protected function create(array $data)
    {
    $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
        'firstName' => $data['firstName'],
            'lastName' => $data['lastName'],
            'password' => bcrypt($data['password']),
        ]);

    $user->userProfile = $data['firstName'] . ','. $data['lastName'] . ',' . $user->id; // Separate call to get ID for user 

    return $user;
    }

Hope this helps.

Neil

neilherbertuk left a reply on Extend Service Provider With Views, Which Append Layout.app • 4 months ago

Hi devapp,

First question, where are you using the loadViewFrom method? Is this from within the package your trying to use? To me, it sounds like you are trying to use it a bit backwards. Your main views should always be available. The loadViewsFrom method should be pointing at your packages views.

The second parameter within the loadViewsFrom method gives the views a namespace. Anything you load using this method and a second parameter would be called from the namespace e.g. "theme-xxx::viewname" instead of just "viewname". So within your controller you would use

return view('theme-xxx::name_of_view_within_package")

From info on this can be found at https://laravel.com/docs/5.4/packages#views

Hopefully that points you in the right direction to fix this.

Neil

20th May, 2017

neilherbertuk left a reply on How To Use Session In Laravel • 4 months ago

Hi ashwinip,

Everything you need to know about using sessions can be found on the Laravel Documentation at https://laravel.com/docs/session

19th May, 2017

neilherbertuk left a reply on Separating The Rows' Owner On Database. • 4 months ago

Hi chorajunior,

This sounds like something you can do by overwriting the newQuery() method on your product model. As long as you have a relation between the customer and the product. This will ensure that every call to the Products model will have the Where customer_id=$customer->id tacked on.

''' public function newQuery() { return parent::newQuery() ->where('customer_id', $customer->id) } '''

Edit Your Profile
Update

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