splendidkeen

Experience

12,730

2 Best Reply Awards

  • Member Since 8 Months Ago
  • 43 Lessons Completed
  • 0 Favorites

17th June, 2018

splendidkeen left a reply on Route [login] Not Defined: Auto Logout/ Session End • 1 day ago

Thank you @Snapey

What is meant with I should not be in this function? Within the unauthenticated function, right? I added the case, even though it should handle unauthenticated exceptions, but it did not.

If I edit the render function it works fine, too. How does the default unauthenticated function is structured again?

public function render($request, Exception $exception)
    {   
        $class = get_class($exception);

        switch($class) {
            case 'Illuminate\Auth\AuthenticationException':
                $guard = array_get($exception->guards(), 0);
                switch ($guard) {
                    case 'partner':
                        $login = 'partner.auth.signin';
                        break;
                    default:
                        $login = 'user.auth.signin';
                        break;
                }

                return redirect()->route($login);
        }
    
        return parent::render($request, $exception);
    }

    protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }

        


    }

16th June, 2018

splendidkeen left a reply on Route [login] Not Defined: Auto Logout/ Session End • 1 day ago

After some research, this changed setup works fine after little testing.

public function render($request, Exception $exception)
    {
        $class = get_class($exception);

        switch($class) {
            case 'Illuminate\Auth\AuthenticationException':
                $guard = array_get($exception->guards(), 0);
                switch ($guard) {
                    case 'partner':
                        $login = 'partner.auth.signin';
                        break;
                    default:
                        $login = 'user.auth.signin';
                        break;
                }

                return redirect()->route($login);
        }

        return parent::render($request, $exception);
    }

    protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }


    }

splendidkeen left a reply on Route [login] Not Defined: Auto Logout/ Session End • 2 days ago

Funny, I already adjusted my Handler.php file:

protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }

        $guard = array_get($exception->guards(), 0);

        switch ($guard) {
            case 'partner':
                $login = 'partner.auth.signin';
                break;
            
            default:
                $login = 'user.auth.signin';
                break;
        }

        return redirect()->guest(route('$login'));
    }

but obviously it does not work with the setup. @Snapey

Thank you for the new syntax hint, will update my routes.

splendidkeen left a reply on Route [login] Not Defined: Auto Logout/ Session End • 2 days ago

Hello and thank you @Snapey

Already tested it this way

Route::get('/login', [
    'uses' => '[email protected]', 
    'as' => 'user.auth.signin',
    'name' => 'login',
    'middleware' => ['guest'],
]);

but somehow it did not work out.

Auth middleware would be the Authenticate.php File? Or where is the /login Redirect defined/ would you recommend to change it?

splendidkeen started a new conversation Route [login] Not Defined: Auto Logout/ Session End • 2 days ago

Use cases:

  1. As a logged in User (A), 2 open tabs, I log out on the first tab, then reload a middleware protected Route on the second tab, it returns the login not defined error.
Even though I added (Controller)

$user = Auth::user();
        
        if(!Auth::user()->id === $user->id){

            return redirect()
                ->route('home')
                ->with('info', 'Sorry, looks like something went the wrong way.');
        }

        if(!Auth::check()){
            Auth::logout();
            return redirect()
                ->route('user.auth.signin')
                ->with('info', 'Sorry, looks like something went the wrong way. Sign back in.');
        }
 

Routes:

// User.php (default guard: (web))

Route::get('/login', [
    'uses' => '[email protected]', 
    'as' => 'user.auth.signin',
    'middleware' => ['guest'],
]);

Route::post('/login', [
    'uses' => '[email protected]',
    'middleware' => ['guest'],
]);

Route::get('/logout', [
    'uses' => '[email protected]', 
    'as' => 'user.auth.logout',
]);

// Partner.php (Guard (partner))

Route::prefix('partner')->group(function(){

Route::get('/login', [
    'uses' => '[email protected]', 
    'as' => 'partner.auth.signin', 
    'middleware' => ['guest'],
]);

Route::post('/login', [
    'uses' => '[email protected]',
    'middleware' => ['guest'], 
]);

Route::get('/logout', [
    'uses' => '[email protected]', 
    'as' => 'partner.auth.logout',
]);
});

  1. Same for my second guard, it will return the Route login not defined Error, even though I add this to my Controller, within all protected/ Partner methods.
if(!Auth::user()->id === $partner->id){
                Auth::guard('partner')->logout();
                return redirect()
                    ->route('partner.auth.signin')
                    ->with('info', 'Sorry Partner, looks like something went the wrong way.');
}

if(!Auth::check()->guard('partner')){
                Auth::guard('partner')->logout();
                return redirect()
                    ->route('partner.auth.signin')
                    ->with('info', 'Sorry Partner, looks like something went the wrong way. Sign back in.');
}

Normally it should also redirect to 'home', when a session expired, but somehow it always returns this Error, on both User and Partner system.

Really looking forward to your advice.

7th June, 2018

splendidkeen left a reply on Foreach Loop Based On Events Name • 1 week ago

@snapey I am still playing around the Controller, dd() different collections, but the main difficulty still maintains..

Sorry for the Apples metaphor, but it helps me to simplify the process.

Following the process above, I want to pre-filter data within my Controller and then display specific partials within my view.

$userApple = ['App\Events\UserApple'];  

$collection = Auth::user()->activities()->where('event',  $userApple)->get();  

// Everything top. -> Gives me a collection of the related data (e.g. 2 records for Activity Model)

// Now I want to check on the related model of each of this collection
                
$apple = Auth::user()->apples()->where('id', $collection->model_id)->get();
                    
// gives me the error [model_id] doesnt exist on this model

// If i use first(), it works logically for the first record of the collection 

$apple = Auth::user()->apples()->where('id', $collection->first()->model_id)->get();

// But I need to check / get each `apples`

How can I check the id of the apples Model for each activities() model_id?

splendidkeen left a reply on Foreach Loop Based On Events Name • 1 week ago

I am currently trying to trigger the 'event' name within my Controller. But somehow the collection is null. How can I check on Event names?

Controller

$activityUser1 = Auth::user()->activities()->where('event', 'App\Events\UserCreated')->get();

6th June, 2018

splendidkeen started a new conversation Foreach Loop Based On Events Name • 1 week ago

Hey, I am currently trying to loop through my "Activity.php" Model

activities_table

$table->increments('id');
$table->unsignedInteger('user_id');
$table->string('event');  
$table->unsignedInteger('model_id')->nullable();

It contains records stored by several Event/Listeners.

I now want to display all User.php related activities, and within the foreach loop check the 'event' and then display an Event related partial. My relations work fine, but somehow the foreach logic won't work.

Imagine this process:

We have the Events

App\Events\UserCreated

App\Events\UserApple

Within my view, I want to parse partials based on the 'event' name

@foreach(Auth::user()->activities()->where('user_id', Auth::user()->id)->get() as $activity)

@if($activity->event === 'App\Events\ UserCreated')

... display a UserCreated specific partial

@elseif($activity->event === 'App\Events\ UserApple')

... display a UserApple specific partial

@endif
@endforeach

Somehow this won't work, it counts the activities correctly, but unfortunately displays them within only one 'event'-specific partial. The aim is to visualize activities within a list and for every 'event' display it's own list-style/ partial.

How do I need to structure the foreach loop?

1st June, 2018

splendidkeen left a reply on Event Participation: Call To A Member Function Participants() On Null • 2 weeks ago

Thank you, @Snapey

It worked, as I created a participation as its own model.

31st May, 2018

splendidkeen started a new conversation Event Participation: Call To A Member Function Participants() On Null • 2 weeks ago

Good evening,

I am currently adding a Status logic to Events and their participants. I have two sides. Partner.php who hasMany(Event.php) and User.php who belongsToMany(Event.php). As a User participates within an Event.php, a record will be created within event_participations table (user_id, event_id) turning an interested boolean into 1. Within this table I created a status_id column, to manage the participation presence as a Partner.php.

Partner.php

public function events(){
        return $this->hasMany(Event::class);
    }

    public function participants(){
       return $this->belongsToMany(User::class, 'event_participations', 'event_id', 'user_id'); 
    }

User.php

public function events(){
       return $this->belongsToMany(Event::class, 'event_participations', 'user_id', 'event_id')->withTimestamps(); 
    }

Event.php

public function partner()
    {
        return $this->belongsTo(Partner::class, 'partner_id');
    }

public function participants(){
       return $this->belongsToMany(User::class, 'event_participations', 'event_id', 'user_id'); 
    }

At my Partners Event page, I loop through all participants, including a button to confirm, if User participated

@foreach($event->participants()->wherePivot('interested', true)->get() as $user)

@endforach

The button triggers turning the status_id to 2, in this case, participated:

public function confirmParticipant(Request $request, Event $event, User $user){

        
        $event = Event::where('id', $event->id)->first(); 

        $participant = $event->participants()->id;
        
        $user = $participant->events()->update([ 
            'status_id' => 2, 
        ]);

       
        return redirect()
            ->route('partner.events.show', compact('event'))
            ->with('info', 'You have confirmed the participant.');
        
        }

With the above setup, I am getting this response

Call to a member function participants() on null

What am I missing on this?

29th May, 2018

splendidkeen started a new conversation Event Participation With A Pending Logic • 2 weeks ago

Hello, I am trying to integrate a participation logic with the following process. A Partner hasMany(Event) and User belongsToMany(Event). Currently I am handling participations by turning a participated boolean within my event_participations table to 1, after the User pushed the participate button.

What I now try to implement, is a different logic, where Users participate at my Partners Event, after pushing the participate button, we create a column within event_participations with the user_id and event_id, but participated to 0.

This pending logic will be turned to 1, after my Partner confirmed the participation of $user. I worked it out for User to User friendRequests, but unfortunately I am lacking some ideas how to create it for this particular participation logic.

Later, I want to list all (foreach) participants for my Partner at the Event page with the possibility to confirm participation or not.

This is my current setup:

Participant.php

public function participants(){
        return $this->belongsToMany(User::class, 'event_participations', 'user_id', 'event_id');
    }
 
    public function events(){
        return $this->belongsToMany(Event::class, 'event_participations', 'event_id', 'user_id');
    }
 
    
    public function confirmedParticipants(){
        return $this->participants()->wherePivot('participated', true)->get();
    }

    public function participationRequests(){
        return $this-> events()->wherePivot('participated', false)->get();
    }

    public function participationRequestPending(){
        return $this->participants()->wherePivot('participated', false)->get();
    }


    public function hasParticipationRequestPending(User $user){
        return (bool) $this->participationRequestPending()->where('id', $user->id)->count();
    }

    public function hasParticipationRequestReceived(Event $event){
        return (bool) $this->participationRequests()->where('id', $event->id)->count();
    }

    public function addParticipation(Event $event){
        $this->classes()->attach($event->id);
    }
    
    public function deleteParticipation(Event $event){
        $this->classes()->detach($event->id); 
    }


    public function confirmParticipation(User $user){
        $this->participationRequests()->where('id', $user->id)->first()->pivot->update([
            'participated' => true,
        ]);
    }

    public function particpatedUser(Event $event){
        return (bool) $this-> events()->where('id', $user->id)->count();
    }

splendidkeen left a reply on Addresses Model Inside Maps • 2 weeks ago

Yes, relationship is provided.

User.php

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

Address.php

public function users()
    {
      return $this->hasMany(User::class);
    }

Controller

$user = User::with('address')->get();

Error

Method Illuminate\Database\Eloquent\Collection::address does not exist.

splendidkeen left a reply on Addresses Model Inside Maps • 2 weeks ago

Hey @Cronix

Thank you. Unfortunately with this setup, myMaps will not be displayed anymore.

splendidkeen started a new conversation Addresses Model Inside Maps • 2 weeks ago

Hey,

I am geocoding addresses within my application. Latitude and Longitude are stored within my addresses_table belonging to a User.php

How can I insert the values dynamically into my maps.blade.php View?

Unfortunately, the following setup won't work

function myMap() {
var mapProp= {
    center:new google.maps.LatLng({{$user->address()->latitude}},{{$user->address()->longitude}}),
    zoom:5, 
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}


Anyone has experience on Maps? Thank you

splendidkeen started a new conversation Event Participation Logic W/ Pending Instance • 2 weeks ago

Hello, I am trying to integrate a participation logic with the following process. A Partner hasMany(Event) and User belongsToMany(Event). Currently I am handling participations by turning a participated boolean within my event_participations table to 1, after the User pushed the participate button.

What I now try to implement, is a different logic, where Users participate at my Partners Event, after pushing the participate button, we create a column within event_participations with the user_id and event_id, but participated to 0.

This pending logic will be turned to 1, after my Partner confirmed the participation of $user. I worked it out for User to User friendRequests, but unfortunately I am lacking some ideas how to create it for this particular participation logic.

This is my current setup:

Participant.php

public function participants(){
        return $this->belongsToMany(User::class, 'event_participations', 'user_id', 'event_id');
    }
 
    public function events(){
        return $this->belongsToMany(Event::class, 'event_participations', 'event_id', 'user_id');
    }
 
    
    public function confirmedParticipants(){
        return $this->participants()->wherePivot('participated', true)->get();
    }

    public function participationRequests(){
        return $this-> events()->wherePivot('participated', false)->get();
    }

    public function participationRequestPending(){
        return $this->participants()->wherePivot('participated', false)->get();
    }


    public function hasParticipationRequestPending(User $user){
        return (bool) $this->participationRequestPending()->where('id', $user->id)->count();
    }

    public function hasParticipationRequestReceived(Event $event){
        return (bool) $this->participationRequests()->where('id', $event->id)->count();
    }

    public function addParticipation(Event $event){
        $this->classes()->attach($event->id);
    }
    
    public function deleteParticipation(Event $event){
        $this->classes()->detach($event->id); 
    }


    public function confirmParticipation(User $user){
        $this->participationRequests()->where('id', $user->id)->first()->pivot->update([
            'participated' => true,
        ]);
    }

    public function particpatedUser(Event $event){
        return (bool) $this-> events()->where('id', $user->id)->count();
    }

What should I adjust on my User Model and what on my Event Model? Do i need the Participant Model?

24th May, 2018

splendidkeen left a reply on Partner Uploads: Syntax Error, Unexpected 'if' (T_IF), Expecting ']' • 3 weeks ago

Sorry @tykus

I confusingly displayed my problem.

I am aware of the array error, it only works with requesting inputs within the if/else condition to update or create a model related row.

How is this possible with for Uploads?

splendidkeen started a new conversation Visual.php Model For Partner Uploads • 3 weeks ago

Hello,

I am planning to organize Partner Uploads within a visuals_table. If the Partner uploads a visual, it would check if a visuals Model for this Partner already exists and then handle the upload. Later with an UploadJob.

How could I structure my Method, so that whenever a Partner uploads a Visual, to e.g. store_path within the visuals table, it will update the column, if one exists and if not it will create a row, to store the filename under store_path?

Currently I am seeing an Error for this setup:

Visual.php

    protected $table = 'visuals';    
    protected $fillable = [ 
       
        'partner_id', 'store_path', 'instore_path', 'culture_path', 'trust_path', 'team_path',
    ];

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

post Method

if(Visual::where('partner_id', $partner )->count()) {
                       Visual::where('partner_id',$partner)->update([
                           if($request->hasFile('store_path')){

                            $partner = Auth::user();
                            $image   = $request->file('store_path');            
                            $filename = time() . '.' . $image->getClientOriginalExtension();            
                            $location = public_path('uploads/partners/visuals/'. $filename );           
                            Image::make($image)->resize(812, null, function ($constraint){$constraint->aspectRatio();})->save($location);
                            
                            $image = new Visual(['store_path' => $filename]);
                               
                            $partner->visuals()->store_path = $filename;
                            $partner->save(); 
                        }  
                       ]);
                     } else{
                       
                     $visual = Auth::user()->visuals()->create([
                        if($request->hasFile('store_path')){

                            $partner = Auth::user();
                            $image   = $request->file('store_path');            
                            $filename = time() . '.' . $image->getClientOriginalExtension();            
                            $location = public_path('uploads/partners/visuals/'. $filename );           
                            Image::make($image)->resize(812, null, function ($constraint){$constraint->aspectRatio();})->save($location);
                            
                            $image = new Visual(['store_path' => $filename]);
                               
                            $partner->visuals()->store_path = $filename;
                            $partner->save(); 
                        }  
                     ]);

 }

Error

Parse error: syntax error, unexpected 'if' (T_IF), expecting ']'

5th May, 2018

splendidkeen left a reply on Openhours Logic On Partner Model • 1 month ago

Solved:

<p>@if(Carbon\Carbon::today()->dayOfWeek == 6){{$partner->openhour()->first()->monday_end}} @endif </p>

splendidkeen started a new conversation Openhours Logic On Partner Model • 1 month ago

Hey,

I am trying to create a simple logic for showing the opening hours for a Partner, today. With the following setup, it won't get a string, but lists a grey boxed collection Partner.php:69:int 6

Any recommendations to solve this?

show.blade.php

<p>Open until  {{$partner->opentoday($partner)}}</p>

Partner.php

public function opentoday(Partner $partner){

        $dt = Carbon\Carbon::today();

        if(var_dump($dt->dayOfWeek) == 1){
            
            $hour = Carbon\Carbon::parse(optional($partner->openhour()->first())->monday_end)->format('H:i A');

        } elseif (var_dump($dt->dayOfWeek) == 2) {

            $hour = Carbon\Carbon::parse(optional($partner->openhour()->first())->tuesday_end)->format('H:i A');

        } elseif (var_dump($dt->dayOfWeek) == 3) {

            $hour = Carbon\Carbon::parse(optional($partner->openhour()->first())->wednesday_end)->format('H:i A');

        } elseif (var_dump($dt->dayOfWeek) == 4) {

            $hour = Carbon\Carbon::parse(optional($partner->openhour()->first())->thursday_end)->format('H:i A');

        } elseif (var_dump($dt->dayOfWeek) == 5) {

            $hour = Carbon\Carbon::parse(optional($partner->openhour()->first())->friday_end)->format('H:i A');

        } elseif (var_dump($dt->dayOfWeek) == 6) {

            $hour = Carbon\Carbon::parse(optional($partner->openhour()->first())->saturday_end)->format('H:i A');

        } elseif (var_dump($dt->dayOfWeek) == 0) {

            $hour = Carbon\Carbon::parse(optional($partner->openhour()->first())->sunday_end)->format('H:i A');

        } else{

            $hour = 'Soon more';
        }

    }

1st May, 2018

splendidkeen left a reply on Incorrect Integer Value • 1 month ago

I need the selected options, value which represents a doctors ID. @Vilfago

splendidkeen started a new conversation Incorrect Integer Value • 1 month ago

Quick question:

I am looping through all available doctors:

<select id="select" name="select" >
@foreach($product->partner->doctors()->where('available', 1)->get() as $doctor)
          <option value="{{$doctor->id}}">{{$doctor->name}}</option> 
@endforeach 
</select>

How can I get the value within my Controller?

// General error: 1366 Incorrect integer value

$request->select === '{{$doctor->id}}';
        
$doctor = $meeting->doctor_id = '{{$doctor->id}}';

$meeting->save();

splendidkeen left a reply on Meeting Token/ Booked Implementation • 1 month ago

I am looping through all available doctors:

<select id="select" name="select" >
@foreach($product->partner->doctors()->where('available', 1)->get() as $doctor)
          <option value="{{$doctor->id}}">{{$doctor->name}}</option> 
@endforeach 
</select>

How can I get the value within my Controller?

// Incorrect integer value;

$request->select === '{{$doctor->id}}';
        
$doctor = $meeting->doctor_id = '{{$doctor->id}}';

$meeting->save();

29th April, 2018

splendidkeen left a reply on Meeting Token/ Booked Implementation • 1 month ago

Great. Thank you @bobbybouwmann

splendidkeen left a reply on Meeting Token/ Booked Implementation • 1 month ago

Thank you @bobbybouwmann

Great direction, I will try it out.

splendidkeen left a reply on Meeting Token/ Booked Implementation • 1 month ago

Cool , so within the create Method, I would check something like

$meeting_time = $meeting-> time && $meeting->date && $meeting->doctor_id;

if($meeting_time  === NULL){

    // create Meeting because there is space
} else {

    return "Sorry, for this date/time combination Doctor z is not available. Check an hour later..."

}

How can I add that the slot books a time + 1 hour slot in the system, so when the doctor has a Meeting at 12:00 it is not possible to book something within at least the next hour?

splendidkeen left a reply on Meeting Token/ Booked Implementation • 1 month ago

Hello @bobbybouwmann

I would only show Doctors which are available, so the Partners adjust availability through a boolean logic at the doctors Model. Then I would show an foreach option of $doctors->where('availability' => 1), meaning available for the whole day, as the first Meeting restriction.

But what if the available Doctor already has a Meeting at 12:00 AM? I could display a collection of the Meetings on the chosen day, but it wouldn't restrict it in the system.

So based on date/time and doctor, I would check availability within the Meetings table?

This is my Meetings table:

public function up()
    {
        Schema::create('meetings', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id');
            $table->integer('partner_id'); 
            $table->integer('doctor_id'); 
            $table->time('time');
            $table->date('date'); 
            $table->boolean('success')->nullable();
            $table->boolean('archived')->nullable();
            $table->timestamps();
        });
    }

splendidkeen started a new conversation Meeting Token/ Booked Implementation • 1 month ago

Hello,

I am currently testing a sort of Meeting System, where a User.php hasMany Meeting.php at a Partner.php. A User can choose a Time for Today, Tomorrow or Today +2, 'time' => 'date_format:H:i|max:140',, and a preferred Doctor.php. The Meeting then belongs to the User, and Doctor.

 $this->validate($request, [ 
            'time' => 'date_format:H:i|max:140', 
        ]);

        // Data Creation 

        $meeting = Auth::user()->meeting()->create([
            'partner_id' => $partner->id, 
            'user_id' => auth()->user()->id,  
        'time' => $request->input('time'),
        ]);
 

         // Date Select

        if ($request->select === '0') {

            $date = $meeting->date = Carbon\Carbon::today();

            $meeting->save();

        }  elseif ($request->select === '1') { 

            $genre = $meeting->date = Carbon\Carbon::tomorrow();

            $meeting->save();

        } else{

            $date = $meeting->date = Carbon\Carbon::today()->addDays(2);

            $meeting->save();
        }

    // Doctor Select (will be equal to Date Select, but should only show available Doctors)



    // How can I implement a Logic in which only available Doctors will be displayed and create tokens for already chosen/ booked times for date x && time y with Doctor z, telling the User that they should choose another time?
    

28th April, 2018

splendidkeen left a reply on Get Hours For Today, If Today == E.g. Friday • 1 month ago

Hey, thanks first @cre3z

Current Update

Type error: Too few arguments to function for Partner::openhour() 

Partner.php

public function openhour()
    {
      return $this->hasMany(Openhour::class);
    }

public function opentoday(Partner $partner, Openhour $openhour){

        $dt = Carbon\Carbon::today();

        if(var_dump($dt->dayOfWeek) == 1){
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->monday_end)->format('H:i A');
        } elseif (var_dump($dt->dayOfWeek) == 2) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->tuesday_end)->format('H:i A');
        } elseif (var_dump($dt->dayOfWeek) == 3) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->wednesday_end)->format('H:i A');
        } elseif (var_dump($dt->dayOfWeek) == 4) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->thursday_end)->format('H:i A');
        } elseif (var_dump($dt->dayOfWeek) == 5) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->friday_end)->format('H:i A');
        } elseif (var_dump($dt->dayOfWeek) == 6) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->saturday_end)->format('H:i A');
        } elseif (var_dump($dt->dayOfWeek) == 0) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->sunday_end)->format('H:i A');
        } else{
            return "Soon more";
        }

    }

splendidkeen started a new conversation Get Hours For Today, If Today == E.g. Friday • 1 month ago

Hey, I could need some help with a little opening hours logic. I want to display how long Partner x is open today. How can I replace the == e.g. monday correctly?

View

<p>Open until {{$partner->open()}}</p>

Partner.php

public function open(){

        if(Carbon\Carbon::today() == monday){
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->monday_end)->format('H:i A');
        } elseif (Carbon\Carbon::today() == tuesday) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->tuesday_end)->format('H:i A');
        } elseif (Carbon\Carbon::today() == wednesday) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->wednesday_end)->format('H:i A');
        } elseif (Carbon\Carbon::today() == thursday) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->thursday_end)->format('H:i A');
        } elseif (Carbon\Carbon::today() == friday) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->friday_end)->format('H:i A');
        } elseif (Carbon\Carbon::today() == saturday) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->saturday_end)->format('H:i A');
        } elseif (Carbon\Carbon::today() == sunday) {
            return Carbon\Carbon::parse(optional($partner->openhour()->first())->sunday_end)->format('H:i A');
        } else{
            return "Soon more";
        }

    }

26th April, 2018

splendidkeen left a reply on - • 1 month ago

Sorry for deleting, the problem was related to a column which was requested in the form but not mentioned in the Model which resulted in -> General error: 1364 Field 'city' doesn't have a default value

splendidkeen started a new conversation Production Form Results In Error • 1 month ago

I am currently testing a simple User signup. In production, the form results in the default grey "Whoops" error page. When I test the form in development, it works.

User.php


class User extends Model
{
    use Notifiable;

    protected $table = 'users';
    
    
    protected $fillable = [

        'email', 
        'name', 
        'country',
        'city',
        'street',
        'name', 
    ];

}

public function postBeta(Request $request){

        $this->validate ($request, [
            'email' => 'required|email|unique:users|max:200',
            'street' => 'required|max:40',
            'name' => 'required|max:50',
            'country' => 'required|max:38',
            'city' => 'required|max:28', 
            
        ]);

        $user = User::create([
            'email' => $request->input('email'), 
            'street' => $request->input('street'),
            'name' => $request->input('name'),
            'country' => $request->input('country'),
            'city' => $request->input('city'), 
        ]);
 

        return redirect()
            ->route('thanks');
    }

The form is on located at home.blade.php and redirects to thanks.blade.php

Route::get('/', [
    'uses' => '[email protected]', 'as' => 'home',

    ]);
 

Route::post('/', [
    'uses' => '[email protected]',
    'middleware' => ['guest'],
    ]);


home.blade.php

<form class="log-form" role="form" method="post" action="/"> 
                <div>  
                <p>Sign up</p> 
                </div> 
                    <div class="form-group{{ $errors->has('email') ? ' has-error' : ''}}">
                      <label class="label-sign">Email</label>
                      <input type="text" name="email" value="{{ Request::old('email') ?: ''}}" placeholder="[email protected]">
                      @if ($errors->has('email'))
                        <span class="help-block-2">{{ $errors->first('email')}}</span>
                      @endif
                    </div>
                    <div class="form-group{{ $errors->has('name') ? ' has-error' : ''}}">
                      <label class="label-sign">Name</label>
                      <input type="text" name="name" value="{{ Request::old('name') ?: ''}}" placeholder="First and Last Name">
                      @if ($errors->has('name'))
                        <span class="help-block-2">{{ $errors->first('name')}}</span>
                      @endif
                    </div>
                    
            .....

                    <div class="form-group">
                      <button type="submit" class="submit-button log-button">Join</button> 
                    </div>
                    <input type="hidden" name="_token" value="{{ Session::token()}}">
</form>

20th April, 2018

splendidkeen left a reply on Image Source Not Readable (Upload Job Exception) • 1 month ago

The folder structure is provided as /uploads/partners/logos/at aws. @rin4ik

19th April, 2018

splendidkeen left a reply on Image Source Not Readable (Upload Job Exception) • 1 month ago

No. The Job now only processes/ attempts once, but still not readable.

splendidkeen left a reply on Image Source Not Readable (Upload Job Exception) • 1 month ago

The Upload Job fails again.

The image will be stored locally as a folder.

splendidkeen left a reply on Image Source Not Readable (Upload Job Exception) • 1 month ago

Now we are getting: Call to a member function move() on null

So the problem is the location.

splendidkeen left a reply on Image Source Not Readable (Upload Job Exception) • 1 month ago

This gives me Image source not readable as an Error page + failed Job.

splendidkeen left a reply on Image Source Not Readable (Upload Job Exception) • 1 month ago

Also tried:

$partner->logo_filename = '/uploads/partners/logos/' . $filename;

splendidkeen left a reply on Image Source Not Readable (Upload Job Exception) • 1 month ago

Still not readable.

splendidkeen left a reply on Image Source Not Readable (Upload Job Exception) • 1 month ago

No, this won't work either. Same with uploading the file to storage_path...

splendidkeen left a reply on Image Source Not Readable (Upload Job Exception) • 1 month ago

Hey and yes @rin4ik

splendidkeen started a new conversation Image Source Not Readable (Upload Job Exception) • 1 month ago

I am trying to handle uploads this way:

First upload the requested file locally, then trigger a UploadLogo Job to push the file to S3 and delete the local pathed-file.

I am always getting this exception:

Intervention\Image\Exception\NotReadableException: Image source not readable 
...

This is my setup:

UploadLogo.php (Job)

public $partner;
public $filename;
    

public function __construct($partner, $filename)
{
        $this->partner = $partner;
        $this->filename = $filename;
}

public function handle()
{
        $path = public_path() . '/uploads/partners/logos/' . $this->filename;
        $filename = $this->filename;

        if (Storage::disk('s3')->put('/uploads/partners/logos/'. $filename, fopen($path, 'r+'))) {
            File::delete($path);
        }
 
        $partner->logo_filename = $filename;
        $partner->save();
}

UploadController.php

public function uploadLogo(Request $request, Partner $partner){

//Validation...

if($request->hasFile('logo')){
    if ($request->file('logo')->isValid()) {
        $partner = Auth::user();

        $image = $request->file('logo');

        $filename = time() . '.' . $image->getClientOriginalExtension();
        $location = public_path('uploads/partners/logos/'. $filename);
        Image::make($image)->resize(300,300)->save($location);

        $partner->logo_filename = $filename;
        $partner->save();
                           
        $this->dispatch(new UploadLogo($partner, $filename));
    }

//Redirect with Info

}
}

12th April, 2018

splendidkeen left a reply on Geocode Address (Geocode Job) • 2 months ago

It now spits no error, but my Job is processing 255 attempt to Geocode the Address without failing. I had the similar problem with another job, when running php artisan queue:work.

@Helmchen

splendidkeen left a reply on Geocode Address (Geocode Job) • 2 months ago

Thank you @Helmchen

$apiKey is provided within config file.

I structured it this way, now:

GeocodePartnerAddress.php (Job)

public function handle()
    { 

        $geocoder = new Geocoder($client);

        $result = $geocoder->getCoordinatesForAddress("{$partner->street}, {$partner->city}");

        Address::create([
            'partner_id' => $partner->id,
            'latitude' => $result['lat'],
            'longitude' => $result['lng']
        ]);

    }

createPartner Method

$client = new GuzzleHttp\Client();

dispatch(new GeocodePartnerAddress($client));

Now I am getting this Error:

"Serialization of 'Closure' is not allowed"

splendidkeen left a reply on Geocode Address (Geocode Job) • 2 months ago

@Helmchen

'providers' => [
    '...',
    Spatie\Geocoder\GeocoderServiceProvider::class
];


'aliases' => array(
    ...
    'Geocoder' => Spatie\Geocoder\Facades\Geocoder::class,
)

splendidkeen left a reply on Geocode Address (Geocode Job) • 2 months ago

The geocoder package return an array, when using getCoordinatesForAddress

$geocoder->getCoordinatesForAddress('Infinite Loop 1, Cupertino', $apiKey);

/* 
  This function returns an array with keys
  "lat" =>  37.331741000000001
  "lng" => -122.0303329
  "accuracy" => "ROOFTOP"
....

I wanted to request the values and save them within the Address table like:

$address = Auth::user()->address()->create([
            'partner_id' => auth()->user->id, 
        'latitude' => $request->input('lat'), 
        'longitude' => $request->input('lng'),
]);

splendidkeen started a new conversation Geocode Address (Geocode Job) • 2 months ago

I am trying to geocode my Partners address with a job, when they signup and store latitude and longitude within an Addresses table

Therefore, I am using a Geocoder Package.

I am lacking the ability to grab the coordinates and store them within the table. Within my Job I want to trigger the values but somehow it won't grab them.

Address.php

protected $fillable = [ 
        'id', 'partner_id', 'latitude', 'longitude',
];

public function partner()
{
      return $this->hasMany(Partner::class);
}
    

Partner.php

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

AuthPartnerController (Signup Method)

Partner::create([
            ....
            'zip' => $request->input('zip'),
            'street' => $request->input('street'),
            'city' => $request->input('city'),
            'country' => $request->input('country'), 
             ...
])));

dispatch(new GeocodePartnerAddress($partner));

GeocodePartnerAddress (Job)

protected $partner;

public function __construct($partner)
{
        $this->partner = $partner;
}

public function handle()
{
        $geocoder = new Geocoder($partner);

        Address::create($geocoder->getCoordinatesForAddress('{{$partner->street}}, {{$partner->city}}', $apiKey));

        'partner_id' => auth()->user->id, 
        'latitude' => $request->input('lat'), 
        'longitude' => $request->input('lng'),

}

9th April, 2018

splendidkeen left a reply on Route: Wildcard Issue • 2 months ago

Yes. Partner has a column within its table with genre_id, referring to the partner_genres Table (id, genre, timestamp) where the genre is the value I am aiming to pass before the partners name within the Url. @rin4ik

splendidkeen left a reply on Route: Wildcard Issue • 2 months ago

How can I access the genre() value, if a Partner belongsTo a Genre?

E.g. when the Partners (partners_table) Name = Test and the (partners_table) genre_id = 1 which relates to (partner_genres_table) id=1, genre=apple.

Right now, when I visit /test/apple by typing it manually it misses the Partners variable.

splendidkeen left a reply on Route: Wildcard Issue • 2 months ago

@bashy

Then it would only work if I create multiple routes, and name the first route param after the genre, then add the model instance with a restriction to $partner genre_id within the Controller?

splendidkeen left a reply on Route: Wildcard Issue • 2 months ago

partner/user/show.blade.php

<div class="container">
<h1>{{$partner->name}}</h1>
</div>
Edit Your Profile
Update

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