jkoech

Experience

5,250

3 Best Reply Awards

  • Member Since 4 Years Ago
  • 21 Lessons Completed
  • 1 Favorite

16th February, 2018

jkoech left a reply on Redirect User To /createPost Page After He Registers • 2 months ago

Laravel >= 5.3

Modify the new Middleware auth redirector

/app/Http/Middleware/RedirectIfAuthenticated.php

Change the handle function slightly, so it looks like:

public function handle($request, Closure $next, $guard = null)
{
    if (Auth::guard($guard)->check()) {
        return redirect()->intended('/home');
    }

    return $next($request);
}

18th December, 2017

jkoech left a reply on Breaking Out Of A Foreach • 4 months ago

This is really bad. Iterating means will be queried foreach time the loop is executed. Why can't you tell us what you are trying to achieve and we can suggest a better approach.

17th December, 2017

jkoech left a reply on Php Artisan Make:auth Doesn't Create Controllers • 4 months ago

When you run the command php artisan make:auth, what do you see on your terminal/command-line?

jkoech left a reply on Install Pacakge In Laravel App On Cpanel • 4 months ago

You can download the app from cpanel, set it up on your local developer environment, install the package via composer the reupload the app.

jkoech left a reply on Need Opinions On Database Design For Roles & Permissions • 4 months ago

The reason the second approach is favourable is because of scalability. You won't have any issues in the long-run. I highly recommend the second approach since it has been my go-to approach for most of my projects.

When running your queries, just eagerload the relationship. Eager loading alleviates the N + 1 query problem.

jkoech left a reply on 1and1 Shared Hosting - Quick Comment • 4 months ago

What is the issue with 1and1?

9th December, 2017

jkoech left a reply on Problem Searching Relation Using Yajra Datatables • 4 months ago

I manage to solve the problem with the code below:

$brands = Brand::with('categories')
            ->select('brands.*')
            ->whereHas('categories', function ($q) use ($request) {
                if ($request->has('categories') && $request->get('categories') != null ) {
                    $categories = array_filter($request->categories);
                    if(count($categories) > 0) {
                        //$q->where('categories.slug', '=', $request->categories);
                        $q->whereIn('categories.slug', $request->get('categories'));
                    }  
                }
                
            });

8th December, 2017

jkoech left a reply on .htaccess Easy Problem • 4 months ago

The problem is not htaccess, you are missing a blade file. Create the file under resources->views->carriers>sections->footers.blade.php

jkoech started a new conversation Problem Searching Relation Using Yajra Datatables • 4 months ago

I have a Brand and Category model, with a many to many relationship. In my Brand Model, I have the following relation:

public function categories()
{
    return $this->belongsToMany(Category::class);
 }

And in my Category model, I have:

public function brands()
{
    return $this->belongsToMany(Brand::class);
}

Everything is working fine, I can search any field in the Brand Model except I haven't been able to search the Category. Below is my code, please help:

$brands = Brand::with('categories')->select('brands.*');

return Datatables::of($brands)
    ->filter(function ($query) use ($request) {

        if ($request->has('brand')) {
            $query->where('brand', 'like', "%{$request->get('brand')}%");
        }

    if ($request->has('category')) {
            $query->whereHas('categories', function ($q) use ($request) {
                $q->where('categories.slug', $request->category);
            });
        }

      
    })->make(true);

4th December, 2017

jkoech started a new conversation Custom Filter On Laravel 5.5 Using Yajra Datatables Package • 4 months ago

I followed this guide https://datatables.yajrabox.com/fluent/custom-filter (all the code is available on the link) on implementing a custom search box. Now I have certain fields which are checkboxes and a user can tick several check boxes. I'm stuck on how I can iterate multiple multiple checkboxes and input fields. Anyone done this before? @yajra could please help if you can? TIA.

jkoech left a reply on Sending Mail On Laravel To Gmail • 4 months ago

@king_eke will find sometime to share. Meanwhile, just use sendmail as the mail driver, it saved me the hassle in some project.

3rd December, 2017

jkoech left a reply on New Image Folder Not Found, Laravel Boilerplate • 4 months ago

Post the error that shows on your browsers console.

jkoech left a reply on Suggestions For Finding Laravel Developer For Saas Guidance • 4 months ago

You could contact some Laravel devopers on this forum. Most have their contact info on their profiles.

jkoech left a reply on Sending Mail On Laravel To Gmail • 4 months ago

Enable 2FA on your gmail and use 2FA password. I had the same issue too. Seems like enabling less secure apps makes Google to block any SMTP connection on that account.

2nd December, 2017

jkoech left a reply on Problem Installing Laravel On Remote Server (DO) With Composer Install • 4 months ago

Try removing or renaming the 'vendor' folder and run composer install

jkoech left a reply on Why Is Laravel Not Running In Wamp? • 4 months ago

Does CSS and other files load?

jkoech left a reply on Login Redirect Not Working In 5.5? • 4 months ago

If you want to redirect after login, add the following method in your LoginController.php

protected function authenticated(Request $request, $user)
{
    return redirect('/redirect-url'); //put your redirect url here
}

30th November, 2017

jkoech left a reply on Laravel In A Subdirectory And Phpunit Gives Always 404 • 4 months ago

If you visit http://localhost/project1/public, are you able to see the website?

29th November, 2017

jkoech left a reply on Multiple Users And Signup Forms • 4 months ago

Retrieve an instance of your billable model, have a look at https://laravel.com/docs/5.5/billing#creating-subscriptions

jkoech left a reply on Multiple Users And Signup Forms • 4 months ago

What you can do, just use one Controller, say users, then create a roles table and a pivot table for user_roles. Then in your User table, have nullable fields for all the different user types (admin, users, network, group) then just show the necessary fields on each registration form. This will simplify Cashier integration. I hope this will work.

26th November, 2017

jkoech left a reply on Link Multiple Domains With Multiple Laravel Projects (issue With Nginx) • 4 months ago

As far as I know, you will need each for every site. What's your environment?

jkoech left a reply on Function Authenticate() Not Triggering • 4 months ago

In your login controller have something similar to the below:

protected function authenticated(Request $request, $user)
    {
    if ($user && $user->role === 'admin' || $user->role === 'contributor') {
        return redirect()->route('admin');
    }

     return redirect('/');
    }

Mine works well, just update the conditional.

jkoech left a reply on I've Been Away. • 4 months ago

Welcome back @miiikkeyyyy !

jkoech left a reply on Escape '@' In Config Folder In Laravel • 4 months ago

Just use single quotes.

jkoech left a reply on Issues Loading Player On Laracast • 4 months ago

Never had an issue. Could you try on a different ISP?

jkoech left a reply on Multiple Users And Signup Forms • 4 months ago

Laravel provides a simple way to authorize or restrict user actions https://laravel.com/docs/5.5/authorization.

jkoech left a reply on I Buyed Laravel Spark(unlimited) Recently, Do I Get The Update For Spark 6.0 For Free ? • 4 months ago

Yes, all spark upgrades are always free. Just read through the upgrade guide when the next version is released.

jkoech left a reply on Eloquent Relationships • 4 months ago

Hi Wreed, would you post your migration to make it clear?

24th November, 2017

jkoech started a new conversation Trying To Get Property Of Non-object • 4 months ago

I have the following in my BrandRequest, I expect to get a collection but instead, I only get a string when I dd the $brand. What could be the problem?


namespace App\Http\Requests;

class BrandRequest extends Request
{
    /**
     * Get the Validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        dd($this->brand);
        $id = $this->brand ? ',' . $this->brand->id : '';

        return $rules = [
            'brand' => 'bail|required|max:255',
            'mind_share' => 'bail|required|max:255',
            'slug' => 'bail|required|max:255|unique:brands,slug' . $id,
            'growth_score' => 'nullable|max:255',
            'business_model' => 'nullable|max:255',
        ];
    }
}

8th December, 2016

jkoech left a reply on Eloquent Relationships With Users/Posts/Comments • 1 year ago

Please post your model methods.

jkoech left a reply on Problem With Foreign Key • 1 year ago

@tomi, thank you so much, this worked.

jkoech started a new conversation Problem With Foreign Key • 1 year ago

I'm having problems adding a foreign key to a table using Laravel migrations. One table called 'act_versions' references the id of another table called 'acts'.

Below is the error:

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'act_id' doesn't exist in table (SQL: alter table act_versions add constraint ac t_versions_act_id_foreign foreign key (act_id) references acts (id))

[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'act_id' doesn't exist in table

Below is my acts migration table

class CreateActsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('acts', function (Blueprint $table) {
            $table->increments('id');
            $table->text('act_title');
            $table->string('cap_no', 10);
            $table->string('cap_no_temp', 10);
            $table->string('first_letter', 1);
        });
    }
}

Below is the act_versions migration table


class CreateActVersionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('act_versions', function (Blueprint $table) {
            $table->increments('id');
            $table->foreign('act_id')
                ->references('id')->on('acts');
            $table->date('assent_date');
            $table->string('commencement_date');
            $table->string('version_year', 4);
            $table->string('preamble');
            $table->tinyInteger('is_published');
            $table->tinyInteger('is_deleted');
            $table->timestamps();
        });
    }
}

26th January, 2016

jkoech started a new conversation Laravel 5 RESTful API App With OAuth 2, JWT And Dingo API • 2 years ago

Hello all, This is my first attempt on building a RESTful API. I have a working Laravel 5 application with authentication and would like to extend it to a 3rd party.

Basically, I need to generate a merchant key that will be used by the third party to access the API.

I read through the forum and noticed that OAuth 2.0, JSON Web Token Authentication for Laravel and Dingo were being mentioned a lot.

I understand how each of the above packages work but I'm having a challenge putting them together and having working.

Anyone who's been don this road or would recommend an alternative approach?

9th November, 2015

jkoech left a reply on Help With JQuery Ajax & Laravel 5.1 - Delete Item • 2 years ago

I'm glad it has finally worked! Thank you @bobbybouwmann

jkoech left a reply on Help With JQuery Ajax & Laravel 5.1 - Delete Item • 2 years ago

@bobbybouwmann I've done exactly that but doesn't seem to work either. When a product is added, I can see from the developer tools the divs and it's content but when I click the remove button, it doesn't fire at all.

jkoech started a new conversation Help With JQuery Ajax & Laravel 5.1 - Delete Item • 2 years ago

I building a simple add to cart app. I am able to add products via ajax, I can add multiple without a problem.

My issue is, when I try deleting a product from the cart, the click event doesn't work unless I refresh the page. Even though, I can only delete a single product and the click event doesn't work again until I refresh. What could be the problem?

Here is my code:

/*Code for adding a product to cart when an item is selected from the dropdown list*/
$( "#device_list" ).change(function(e) {
    if($("#device_list").val()) {
        var params=[ 
               {name:"name", value:value1},
               {name:"id", value:value2}
         ];

        $.get("{{ url('api/cart')}}", 
        params, 
        function(data) {
            //empty cart
            $('.mycart').empty;
            
            //reload cart with all new items
            $('.mycart').html(data);

        });
    }
});

And the code for removing an item

$( ".remove-btn" ).click(function(e) {
    var params=[ 
          
           {name:"id", value:$(".remove-btn").attr('id')}
     ];

    $.get("{{ url('api/remove')}}", params, 
    function(data) {
        $('.mycart').empty;
        $('.mycart').html(data);

    });
});

jkoech left a reply on PayPal IPN With Laravel • 2 years ago

Which version of laravel are you using? If using Laravel 5.1, you can do the following: In VerifyCrsfToken.php, add $except as below:

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'stripe/*',
    ];
}

Go to Laravel 5.1 documentation

2nd September, 2015

jkoech left a reply on Php Artisan Migrate:rollback Error • 2 years ago

As @StuffedGoat said, run '' composer autoload

27th May, 2015

jkoech left a reply on Sublime Text - Package That Save Your Time! • 2 years ago

@masandikdev why not upgrade to ST3? :)

26th May, 2015

jkoech left a reply on Tech & Programming News Site • 2 years ago

Plenty of sites available, a few of my favorite shared below:

General Tech sites: https://news.ycombinator.com http://recode.net/

Laravel specific: http://laravel-news.com

Podcasts: http://www.laravelpodcast.com/ http://www.se-radio.net/

And of course always read the official documentations and practice.

jkoech left a reply on Is There Any Document That Describes An RESTful API? • 2 years ago

I don't think a standard documentation exists but you could just follow best practises i.e using RESTful URLs and actions etc. There are plenty of books and guidelines available which will guide you.

14th May, 2015

jkoech started a new conversation Vue.js Tutorials • 2 years ago

@JeffreyWay would you mind doing a quick intro to Vue.js?

jkoech left a reply on Why Laravel Docs Not Good As Codeigniter • 2 years ago

Having a complete example, like the way it's shown on the master documentation, in my opinion is the best way one can easily learn.

13th May, 2015

jkoech left a reply on Laravel 5 Authentication And Roles • 2 years ago

@csuarez yes, I'll did stick with the middleware, I found out that it was really easy stuff.

@ptgokulrajan basically, I didn't change RedirectIfAuthenticated, I just created a new IsRole middleware, i.e IsAdmin.php with something similar to the below:

'''

@param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $user = $request->user(); if ($user && $user->isAdmin()) { return $next($request); } return new RedirectResponse(url('/')); } } '''

21st April, 2015

jkoech left a reply on Elasticsearch Or Solr With Laravel? • 3 years ago

+1 Elastic

13th April, 2015

jkoech started a new conversation [OT] Mac Screencast App • 3 years ago

I'm new to Mac and looking for recommendations for a cool screencast app, like the one @JeffreyWay uses for Laracasts. Thanks.

8th April, 2015

jkoech left a reply on Cross Platform Desktop App, Anything Better Than Node-webkit? • 3 years ago

@isimmons keep me posted on your progress and your evaluation. If it's great, I'll start learning.

Edit Your Profile
Update

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