mattnewark

Experience

4,360

0 Best Reply Awards

  • Member Since 5 Months Ago
  • 10 Lessons Completed
  • 0 Favorites

8th December, 2017

mattnewark left a reply on Laravel Passport And SSL • 4 days ago

So, at the end of a lot of research I have found the answer. If you enter the below in the htaccess file it should for you if the Apache server is striping the auth headers:

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=

Well it has worked for me.

7th December, 2017

mattnewark left a reply on Laravel Passport "Unauthenticated" Error • 4 days ago

If you add this to your htaccess file it should work a treat:

Handle Authorization Header

RewriteCond %{HTTP:Authorization} ^(.) RewriteRule . - [e=HTTP_AUTHORIZATION:%1]

Thanks

mattnewark left a reply on Laravel Authorization Header Is Missing • 4 days ago

Hi @wljin,

Did you solve this issue?

mattnewark left a reply on Deploying Laravel • 5 days ago

@jdunsmore,

I have had it working previously with pointing the domain to the public folder so I am just going to revert everything back to what it was..

Thanks

mattnewark left a reply on Deploying Laravel • 5 days ago

@jdunsmore

I have started to upload everything again,

Thanks for your help

mattnewark left a reply on Deploying Laravel • 5 days ago

Hi

So I have all files apart from the public folder above the public_html in a folder called auditstagingcore, I have emptied the public folder contents into a folder called auditstaging below the public_html. I have also changed the index file to point to the new core folder.

Thanks

mattnewark left a reply on Deploying Laravel • 5 days ago

Hi @jdunsmore

Yes I am

mattnewark started a new conversation Deploying Laravel • 5 days ago

Good Morning All,

I am trying to deploy my site and I have followed the below guide so that I am hiding the core code above the public_html folder:

http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/

The issue that I have now is when I SSH into the folder and try and run the artisan command it doesn't work. I go to the folder core folder and try to run the queue:listen command and it seems to ignore the request. I run php artisan and it doesn't work either, no error.

Can someone please point me in the right direction

Thanks

4th December, 2017

mattnewark left a reply on Arranging Data From A Particular Column In The DB • 1 week ago

Hi,

With help from a few others on larachat, I have done it like this:

public function show($postcode)
    {
        $postcode = str_replace(' ','', $postcode);
        $postcode1 = str_limit($postcode, 5, '');
        $sites = Site::where('spostcode', 'LIKE',  '%'.$postcode1.'%')->orderByRaw("case when spostcode = '{$postcode}' then 1 else 2 end")->get();
        return Fractal::collection($sites, new SiteTransformer);
    }

mattnewark left a reply on Arranging Data From A Particular Column In The DB • 1 week ago

So far I have got this working, I know it isn't the best as I am connecting to the DB twice but i will continue to work through it and find a better option:

public function show($postcode)
    {
        $postcode = str_replace(' ','', $postcode);
        $postcode1 = str_limit($postcode, 5, '');

        $sites1 = Site::where('spostcode', $postcode)->get();
        $sites2 = Site::where('spostcode', 'LIKE',  '%'.$postcode1.'%')->where('spostcode', '<>', $postcode)->get();
        $sites = $sites1->merge($sites2);

        return Fractal::collection($sites, new SiteTransformer);
    }

mattnewark left a reply on Arranging Data From A Particular Column In The DB • 1 week ago

Hi @lostdreamer_nl,

Thanks for your reply, I think that it is working but it is placing the ones at the bottom of the list, how can we have them to the top?

I have tried to use sortBy but this did not work..

Thanks

mattnewark started a new conversation Arranging Data From A Particular Column In The DB • 1 week ago

Hi All,

What I am trying to do is get all the rows from a DB, once I have them then I would like to get the the ones with a particular column first. I can see that this is a little confusing but here is my code:

public function show($postcode)
    {
        $postcode = str_replace(' ','', $postcode);
        $postcode1 = str_limit($postcode, 5, '');

        $sites = Site::where('spostcode', 'LIKE',  '%'.$postcode1.'%')->get();

        return Fractal::collection($sites, new SiteTransformer);
    }

So what I am doing is passing the full postcode to the function and then limiting it to the first 5 characters, which will also bring the ones that match the full postcode as well in the collection. What I need to do is get the ones that match fully to be at the top of the collection.

Can someone please point me in the right direction.

Thanks

30th November, 2017

mattnewark started a new conversation Laravel Passport And SSL • 1 week ago

Hello All,

I am trying to use SSL in passport and I keep getting a unauthenticated response from the API. If I remove the https and only use http it works fine. Has anyone else had the same issue and if so did you resolve it?

Thanks

24th November, 2017

mattnewark left a reply on Return JSON From Multi Level DB • 2 weeks ago

Ok, so after a little more research I have now got the answer:

$stream = Wastestream::with(['Containertypes.Containersizes.Containerunits'])->get();
        return $stream;

mattnewark started a new conversation Return JSON From Multi Level DB • 2 weeks ago

Hello All,

I am trying to do the following with the JSON return:

[  
  {  
     "Stream":{  
        "id":1,
         "name":"Cardboard and Paper Recycling",
         "containertypes":[  
           {  
              "id":37,
               "name":"Front End Loader",
               "pivot":{  
                 "Wastestreams_id":1,
                  "Containertypes_id":37
               },
               "containersize":[  
                 {  
                    "id":32,
                     "name":"1100",
                     "containerunit":[  
                       {  
                          "id":44,
                           "name":"L"
                        }
                     ]
                  }
               ]
            }
     ]
      }
   }
]

but what i am getting is:

 {
        "Stream": {
            "id": 1,
            "name": "Cardboard and Paper Recycling",
            "containertypes": [
                {
                    "id": 37,
                    "name": "Front End Loader",
                    "pivot": {
                        "Wastestreams_id": 1,
                        "Containertypes_id": 37
                    }
                },]}
     "Types": [
            {
                "id": 37,
                "name": "Front End Loader",
                "pivot": {
                    "Wastestreams_id": 1,
                    "Containertypes_id": 37
                }
            }}]
}

My tables are as follows, ``` Containersize, Containertypes, Containerunits,Wastestream``` and the pivot tables are ```Containersizes_Containerunits, Containertypes_Containersizes, Containertypes_Wastestreams```
The models are:
Wastestream:

class Wastestream extends Model { protected $table = 'Wastestreams';

public function Containertypes()
{
    return $this->belongsToMany(Containertype::class, 'Containertypes_Wastestreams','Wastestreams_id','Containertypes_id');
}

public function Wastesubstreams()
{
    return $this->hasMany(Wastesubstream::class,'Wastestreams_id');
}

}

Containertype:

class Containertype extends Model { protected $table = 'Containertypes';

public function Containersizes()
{
    return $this->belongsToMany(Containersize::class, 'Containertypes_Containersizes', 'Containertypes_id', 'Containersizes_id');
}
public function Wastestreams()
{
    return $this->belongsToMany(Wastestream::class, 'Containertypes_Wastestreams','Containertypes_id','Wastestreams_id');
}

}

Containersize:

class Containersize extends Model { protected $table = 'Containersizes';

public function Containertypes()
{
    return $this->belongsToMany(Containertype::class, 'Containertypes_Containersizes', 'Containertypes_id', 'Containersizes_id'); 
}
public function Containerunits()
{
    return $this->belongsToMany(Containerunits::class, 'Containersizes_Containerunits', 'Containersizes_id', 'Containerunits_id');
}

}

Containerunit:

class Containerunit extends Model { protected $table = 'Containerunits';

public function Containersizes()
{
    return $this->belongsToMany(Containersize::class, 'Containersizes_Containerunits', 'Containersizes_id', 'Containerunits_id' );
}

}


In my controller I have the below:

public function GetContainerTypes() { $stream = Wastestream::orderBy('name')->get(); return Fractal::collection($stream, new AuditItemStreamTransformer); }

and in the first Transformer I have:

public function transform(Wastestream $stream) {

    return [

        'Stream' => $stream,
        'Types' => $stream->Containertypes,
    ];
}

public function includetype(Wastestream $stream)
{   
    return $this->collection($stream->Containertypes, new AuditItemSizeTransformer);
}
In the size transformer I have:

public function transform(Containertype $type) { return [

        'Sizes' => $type->Containersizes,
        
    ];
}

public function includeunit(Containertype $type)
{   
    return $this->collection($type->Containerunits, new AuditItemUnitsTransformer);
}
and in the units Transformer:

public function transform(Container $unit) { return [

        'unit' => $unit,
        
    ];
}

If some one could help get the return correct using what I have with DB's that would be wonderful.

Thanks

9th November, 2017

mattnewark left a reply on Flagged Enum • 1 month ago

Hi @Cronix

So are you saying that in the table you would have numbers from 0-6 so if it was Monday and Friday you would have 1 and 5? And so on? And then when you call those numbers back you split them and get the assigned days?

Thanks

mattnewark started a new conversation Flagged Enum • 1 month ago

Hi Everyone,

I am trying to find the best way of having days in a column in the DB, at present for ease we have created 7 columns Monday, Tuesday etc that either have a 1 or a 0, but I was wondering if there is a better way in Laravel that would only have 1 column with all the details like the C# flagged Enum.

Thanks

3rd November, 2017

mattnewark left a reply on Filtering Values With A Key Collection • 1 month ago

Hi @KrzysztofNiepokojczycki,

Thank you for getting back to me, I have been doing this all afternoon and I finally figured it out at the same time you posted. This is what I have, there is a little bit more to what I originally asked for:

$isDeleted = $audit->showItemLast;
            $isDeletedcol = $isDeleted->unique('ParentAuditItemId')->values();
        $isActive = $audit->audititems;
            $audititem = $isDeletedcol->merge($isActive)->all();
            return Fractal::includes('audititemimages')->collection($audititem, new AuditItemTransformer);

I have had to change the model as well to the below:

public function audititems()
    {
        return $this->hasMany(SiteAuditItem::class , 'SiteAudits_id', 'id')->where('isDeleted', null)->orderBy('ParentAuditItemId');
    }
    public function showItemLast()
    {
        return $this->hasMany(SiteAuditItem::class , 'SiteAudits_id', 'id')->orderBy('id', 'desc');
    }

Thanks again.

2nd November, 2017

mattnewark started a new conversation Filtering A Collection • 1 month ago

Good Afternoon all,

I am trying to get the last item in a collection so the scenario goes,

I have a audititem table that has a list of items, when a user clicks delete, the row is flagged as deleted. What I would like to do is be able to bring back the last deleted item to the user.

So so far I have the below:

public function showItemLast(SiteAudit $audit)
    {
        $audit = $audit->showItemLast->where('isDeleted', 1)
                                        ->groupBy('ParentAuditItemId')
                                        ->all();
        return $audit;       
    }

I pass the Audit id to the API and the get the items for that particular audit as shown above.

my audit model looks like:

public function showItemLast()
    {
        return $this->hasMany(SiteAuditItem::class , 'SiteAudits_id', 'id');
    }

It groups all the items based on their parent, what I would like to do is get the last deleted item, I have a created_at column so I can use the time but they do go in id order so it can be the last id of the parentid group.

I will need to put a transformer in when I have it getting the right data.

Hope that makes sense.

Thanks

20th October, 2017

mattnewark left a reply on Many To Many Relationships • 1 month ago

Hi @tykus

I have worked it out and it was an issue on one of the relationships.

Thank you so much for your help

mattnewark left a reply on Many To Many Relationships • 1 month ago

Hi @tykus

I have done the below on the transformer:

dd($AuditItem->images);

and I get the below:

Collection {#261
  #items: []
}

mattnewark left a reply on Many To Many Relationships • 1 month ago

Hi @tykus,

Yes, I get the below but without the images:

{
        "AuditItemId": 133,
        "AuditItemType": "Glass",
        "AuditType": "Bin",
        "audititemimages": []
    },

and my transformer is:

public function includeAuditItemImages(SiteAuditItem $AuditItem)
    {   
        return $this->collection($AuditItem->images, new AuditItemImageTransformer);
    }

Thanks

mattnewark left a reply on Many To Many Relationships • 1 month ago

Hi @tykus

Thanks for the update, I thought that is what was happening just wanted to confirm :)

OK, I am sending Audit ID 12 in Postman and the below is one of the audit Items I have in the DB (SiteAuditItems):

133
12
Check Up
Glass
Bin
1100L
2
This is a note!
2017-10-20 08:42:00
2017-10-20 08:42:00

Then in the pivot table ( SiteAuditImages_SiteAuditItems)

44
133
45
133

I have the images 44 and 45 which I have in the DB (SiteAuditImages).

and to confirm I have the below in my models:

SiteAuditItem:

public function images()
    {
        return $this->belongsToMany(SiteAuditImage::class, 'SiteAuditImages_SiteAuditItems', 'SiteAuditImages_id', 'SiteAuditItems_id');
    }

    public function SiteAudit() 
    {
        return $this->belongsTo(SiteAudit::class, 'SiteAudits_id');
    }

SiteAuditImage

public function SiteAuditItem()
    {
        return $this->belongsTo(SiteAuditItem::class);
    }

    public function items()
    {
        return $this->belongsToMany(SiteAuditImage::class, 'SiteAuditImages_SiteAuditItems', 'SiteAuditImages_id', 'SiteAuditItems_id');
    }

and my SiteAudit

public function audititems()
    {
        return $this->hasMany(SiteAuditItem::class , 'SiteAudits_id', 'id');
    }

Thanks

mattnewark left a reply on Many To Many Relationships • 1 month ago

Hi @tykus

The first DD brings back:

Collection {#240
  #items: []
}

and Empty collection

Could you please explain what yo have done here:

$audit->load('audititems.images');

I'm not sure where audititems and images comes from..

Thanks

mattnewark left a reply on Many To Many Relationships • 1 month ago

@tykus,

That is all I am getting back in Postman, nothing else but []

Thanks

mattnewark left a reply on Many To Many Relationships • 1 month ago

Hi @tykus

So I have added the below to my Audit model:

public function audititems()
    {
        return $this->hasMany(SiteAuditItem::class , 'id', 'SiteAudits_id');
    }

The AuditItem Model:

public function images()
    {
        return $this->belongsToMany(SiteAuditImage::class, 'SiteAuditImages_SiteAuditItems', 'SiteAuditImages_id', 'SiteAuditItems_id');
    }

and when I check it, I get the below:

[]

Thanks

mattnewark left a reply on Many To Many Relationships • 1 month ago

Hi @tykus

Yes that is correct, An audit can be done multiple times at one location and if there are no updates then we will use the same image but add a new line in the DB so that we are able to keep a history of the audits..

Thanks

mattnewark left a reply on Many To Many Relationships • 1 month ago

Hi @Tykus,

$AuditItems is the parent of the images, so what I do is create an Audit then as I go through I add items to the Audit which is the $AuditItems and attached to the items are the images, they link to each other using the pivot table. So when I call the Audit Item and I would like the Audit Images attached to it.

foreach($AuditItems as $ai)
        {
            if($ai->id == 133)
            {
            $item = SiteAuditItem::find($ai->id)->images()->get();
            dd($item);
            }
            // $images = SiteAuditImage::where('SiteAuditItems_id', $ai->pluck('id'))->get();
            //$ai->setAttribute('AuditItemImages', $images);
        }

but what I get is:

Collection {#292
  #items: []
}

I have checked the DB and I have an AuditItem with an id of 133.

Thanks

mattnewark left a reply on Many To Many Relationships • 1 month ago

Hi @tykus,

Sorry that was my miss type, even when I change it to images I still get Method images does not exist.

Thanks

mattnewark started a new conversation Many To Many Relationships • 1 month ago

Hello All,

I am stuck,

my controller:

public function show(SiteAudit $audit)
    {
        $id = $audit->pluck('id');
        $AuditItems = SiteAuditItem::where('SiteAudits_id', $id)->get();
        foreach($AuditItems->image() as $ai)
        {
            // $images = SiteAuditImage::where('SiteAuditItems_id', $ai->pluck('id'))->get();
            $ai->setAttribute('AuditItemImages', $images);
        }
        $result = Fractal::includes('audititemimages')->collection($AuditItems, new AuditItemTransformer);
        return $result;
    }

As you can see from this line // $images = SiteAuditImage::where('SiteAuditItems_id', $ai->pluck('id'))->get(); I need to get the image from the DB but I have now decided that I am going to have to use a pivot table as it will be a many to many relationship with audititems.

my model for AuditItems is:

public function images()
    {
        return $this->belongsToMany(SiteAuditImage::class, 'SiteAuditImages_SiteAuditItems', 'SiteAuditImages_id', 'SiteAuditItems_id');
    }

my model for AuditImages is:

public function items()
    {
        return $this->belongsToMany(SiteAuditImage::class, 'SiteAuditImages_SiteAuditItems', 'SiteAuditImages_id', 'SiteAuditItems_id');
    }

I get "message": "Method image does not exist.", when I try and dd $ai within the foreach.

Can anyone shed a little light on what I am doing wrong.

13th October, 2017

mattnewark left a reply on Passport 'Unauthenticated' • 1 month ago

OK, so after a while and a little help (alot) from the server admins we have found an answer, in the apache config file or .htaccess should have this in it:

RewriteEngine On 
RewriteCond %{HTTP:Authorization} ^(.+)$ 
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

This worked for me.

11th October, 2017

mattnewark started a new conversation Swift_TransportException • 2 months ago

Good Morning all,

I have had my contact form working but now I am getting the below email:

 Swift_TransportException
Connection could not be established with host smtp.office365.com [Connection timed out #110]

I also get the same error when I use the gmail smtp, I have setup our 365 account to allow it from our server and I also changed the setting in gmail to allow less secure connections but this has not made a difference.

My env file is:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=my email
MAIL_PASSWORD=my password
MAIL_ENCRYPTION=TLS

Controller:

public function send(Request $request) {

        $this->validate(request(),[
            'name' => 'required',
            'email' => 'required|email',
            'subject' => 'required',
            'content' => 'required'
        ]);
        $name = $request->name; 
        $email = $request->email;
        $subject = $request->subject;
        $content = $request->content;

        Mail::to($email)
            ->send(new Contact($name, $subject, $content));

            return redirect(url('contact/confirm'));
'''

I have also changed my htaccess file so that forwards all requests to https:

RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

To see if the htaccess file is an issue I have removed the above line and the problem still continues..

Can anyone point me in the right direction to get this resolved.

Thanks


9th October, 2017

mattnewark left a reply on Error On Login After Composer Update • 2 months ago

Not to worry, I have gone back to my original install and it's working.

mattnewark started a new conversation Error On Login After Composer Update • 2 months ago

Hello,

I have had to upgrade to PHP 7 as the site was not working on PHP 5.7 after I update the composer file, now I am having issues logging into the Laravel, the main site works with no issues I get the below error:

ReflectionException (-1)
Class Illuminate\Cache\RateLimiter does not exist

and:

/home/greenzon/public_html/new/vendor/laravel/framework/src/Illuminate/Container/Container.php
    }
 
    /**
     * Instantiate a concrete instance of the given type.
     *
     * @param  string  $concrete
     * @return mixed
     *
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function build($concrete)
    {
        // If the concrete type is actually a Closure, we will just execute it and
        // hand back the results of the functions, which allows functions to be
        // used as resolvers for more fine-tuned resolution of these objects.
        if ($concrete instanceof Closure) {
            return $concrete($this, $this->getLastParameterOverride());
        }
 
        $reflector = new ReflectionClass($concrete);
 
        // If the type is not instantiable, the developer is attempting to resolve
        // an abstract type such as an Interface of Abstract Class and there is
        // no binding registered for the abstractions so we need to bail out.
        if (! $reflector->isInstantiable()) {
            return $this->notInstantiable($concrete);
        }
 
        $this->buildStack[] = $concrete;
 
        $constructor = $reflector->getConstructor();
 
        // If there are no constructors, that means there are no dependencies then
        // we can just resolve the instances of the objects right away, without
        // resolving any other types or dependencies out of these containers.
        if (is_null($constructor)) {
            array_pop($this->buildStack);
 
            return new $concrete;
        }
Arguments
"Class Illuminate\Cache\RateLimiter does not exist"

Can someone please point in the right direct?

Thanks

2nd October, 2017

mattnewark left a reply on Using A Pivot Table • 2 months ago

Hi @Snapey,

All working thank you very much for your help..

28th September, 2017

mattnewark left a reply on Using A Pivot Table • 2 months ago

Hi @snapey,

Would this use the slug in the pivot table? as when I do the dd() i get the beow:

#relations: array:1 [▼
    "bins" => Collection {#242 ▼
      #items: []
    }
  ]

The pivot table is using the services_id and the bins_id, that is why I was trying to get the id for the services or have I got this wrapped round my neck?

THanks

mattnewark left a reply on Using A Pivot Table • 2 months ago

Hi @Snapey

Yes I have a relationship on the services model:

public function bins()
    {
        return $this->belongsToMany(Bins::class);
    }

I thought if I could get the id of the services then I could run the query to get the bins info, how would you write it in one query?

So I need to get the bins details from the bins table and I have a pivot table in the middle with the service id and the bins id. In my view I would like to show the bins that are associated to the service.

When I use your example I get nothing, it's blank:

My bins model is:

public function services()
    {
        return $this->belongsToMany(Services::class);
    }

I would then send the Services ID to the view so that I can loop through the bins:

@foreach($service->bins as $bs)
  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active galleryImage">
      <img src="{{ URL::asset('images/bins/', $bs->link) }}" alt="">
    </div>
@endforeach 

Thanks

27th September, 2017

mattnewark started a new conversation Using A Pivot Table • 2 months ago

Hello All,

Another question,

I am trying to get the id for a particular row when I have another column. I am passing through the slug of the row but I need to get the id so that I am able to send get the details from the pivot table: What I have so far but doesn't seem to work:

$service_id = Services::where('slug', $param)->select('id')->get();

and then what I want to do is pluck the ID of the bins in the pivot table:

$bins_id = Services::find($service_id)->bins->pluck('id');

and then I will get the details of the bins that the service is related too but I seem to be stuck at the this point, can someone please point me in the right direct?

I get this error when I dd($bins_id);.

Property [bins] does not exist on this collection instance.

which can I understand why but I can't get my head around it to get it to work.

Thanks

mattnewark started a new conversation Populating Select With Pivot Data And DB Data • 2 months ago

Hi All,

I need a little help, I have created a pivot table that will hold the ID for Services and Bins I have a select in a blade template that is showing the data in the bins DB, when I select the bins they get put into the pivot table with the services id.

What I would like to do is have an edit form that I can have the list of bins in and have the ones that are selected , selected.

Controller:

 $content = Services::find($id);
        $bins = Bins::all(); 
        return view('admin.services.edit')->with(['content' => $content, 'bins'=> $bins]);

View:

Bins @foreach($bins as $b) {{$b->name}} @endforeach ``` Services Model: ``` public function bins() { return $this->belongsToMany(Bins::class); } ``` Bins Model: ``` public function services() { return $this->belongsToMany(Services::class); } ```

Thanks

25th September, 2017

mattnewark started a new conversation Passport 'Unauthenticated' • 2 months ago

Hi All,

I have searched and search for a resolution to this issue and I am unable to find one, so a little guidance would amazing..

I have setup Laravel passport 5.4 locally and tested it using Postman with no problems but, when I upload to the remote server I get the below response to get the token which is fine:

{
    "token_type": "Bearer",
    "expires_in": 1296000,
    "access_token": "Access token was here",
    "refresh_token": "Refresh token was here"
}

But when I try and go to the protected api url and enter the headers: accept: application/json Authorization: Bearer access_token(copied from the response)

I get:

{
    "error": "Unauthenticated."
}

Has anyone else come across this issue before and if so how did you fix it:

Route/api

Route::get('/todo', '[email protected]')->middleware('auth:api');

Todo controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Todo;

class TodoController extends Controller
{
    public function index()
    {
        return Todo::all();
    }
}

I have followed the laravel passport setup guide and have all the option set.

Thanks

21st September, 2017

mattnewark left a reply on Laravel Passport • 2 months ago

I have gone through the internet for this and we found that the access token was actually was expiring the time it was being created.

what I have done is change the AuthServiceProvider.php and added the below to the boot method:

Passport::tokensExpireIn(Carbon::now()->addDays(15));
        Passport::refreshTokensExpireIn(Carbon::now()->addDays(30));

obviously you will need to have carbon installed but this did the trick and it is working locally..

20th September, 2017

mattnewark started a new conversation Laravel Passport • 2 months ago

Hello Everyone,

So, We are trying to create an API using Laravel Passport, I think I have followed everything that needs to done.

In the client:

We request the access token and we get everything that we need back, but when we try and access an api route after adding the bearer and authentication to the header

Route::get('/todos', 'TodoController')->middleware('auth:api);

and the controller is:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Todo;

class TodoController extends Controller
{
    public function __construct()
    {
       
    }
    public function __invoke()
    {
        return Todo::all();
    }
}

when using Postman to test, we go to the URL and get a response back of unauthenticated even though we have received the access token back.

I have followed the below as well because I couldn't understand what I was doing wrong,

https://scotch.io/@neo/getting-started-with-laravel-passport

Could someone please shed a little light on what I have missed and what I am doing wrong.

Thanks

18th September, 2017

mattnewark left a reply on Symbolic Link • 2 months ago

Morning @sutherland,

Its a long story, I have worked out another way of doing this: So in the filesystem.php I have added the below under disks:

        'uploads' => [
            'driver' => 'local',
            'root'   => public_path() . '/images',
        ],

and then I referenced it in my code :

$icon = $request->icon->getClientOriginalName();
            $main = $request->image->getClientOriginalName();
            $request->icon->storeAs('uploads/icon', $icon, 'uploads');
            $request->image->storeAs('uploads', $main, 'uploads');

Thanks for your help..

15th September, 2017

mattnewark left a reply on Symbolic Link • 2 months ago

hi @sutherland,

For some unknown reason I am unable to access the server do be able to do the command.

Is there another way of getting this work other than making the symbolic link?

Thanks

mattnewark left a reply on Symbolic Link • 2 months ago

Hi @sutherland

Thanks for the info, my remote site is running on a centos box, have you any idea how I would run the artisan cmd to get that working?

Is there another way of doing this?

Thanks

mattnewark started a new conversation Symbolic Link • 2 months ago

Hello All,

I have created a symbolic link for my storage folder so that I am able to see the images that I upload in a view file. Locally I have done the link and it works a treat, I upload a image and it shows in the storage folder and then in the public folder so that I am able to access the images in the view. I have uploaded my changes to my remote server and the link seems to have stopped working, The upload works fine and I am getting the images in the storage folder and in the DB but when I go to the public folder they are not showing.

What am I doing wrong and how can I rectify the issue?

Thanks in advance.

14th September, 2017

mattnewark left a reply on NotFoundHttpException In RouteCollection.php (line 179) • 2 months ago

Thanks @tisuchi,

My mistake.

Thank you

mattnewark left a reply on NotFoundHttpException In RouteCollection.php (line 179) • 2 months ago

Route::get('/admin/news/edit/{$id}', 'Admin\[email protected]')->name('admin.news.edit');

mattnewark left a reply on NotFoundHttpException In RouteCollection.php (line 179) • 2 months ago

Hi @tisuchi

Thanks for the reply,

This has not made a difference, I still get the same error.

mattnewark started a new conversation NotFoundHttpException In RouteCollection.php (line 179) • 2 months ago

Hello All,

I am trying to get the edit to work on my application and I keep getting the above error.

My Routes:

// Routes for Admin
Auth::routes();
Route::get('/admin', 'Admin\[email protected]')->name('admin');
// Routes for Admin\News
Route::get('/admin/news', 'Admin\[email protected]')->name('admin.news');
Route::get('/admin/news/{$id}/edit', 'Admin\[email protected]')->name('admin.news.edit');

Controller:

public function edit($id) 
    {
        $news = News::where('id', $id)->get();
        return view('admin.news.edit', compact('news'));
    }

View:

@extends('layouts.app')
@section('content')
    @foreach ($news as $n)
        {{$n->id}}
    @endforeach
@endsection

Link to the edit view:

<a href="{{ route('admin.news.edit', $n->id) }}" class="btn btn-info">Edit</a>

Can someone please advise why I am getting the error as it seems to me that everything is in the right place.

Thanks

Edit Your Profile
Update

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