msyaukat

Lecturer at IIUM

Experience

3,370

0 Best Reply Awards

  • Member Since 6 Months Ago
  • 22 Lessons Completed
  • 3 Favorites

13th January, 2018

msyaukat left a reply on Redirect With 2 Ids • 3 days ago

done I just hv to call one model. tq

msyaukat left a reply on Redirect With 2 Ids • 3 days ago

if I want to pass this:

return redirect()->route('companybranch.show', [
    'company_id' => $company->company_id, 
    'company_branch_id' => $companybranch->company_branch_id,
]);

that means I need to call:

$company = Company::find($company_id);

in my update controller right? when I did this, it says $company is undefined. How?

11th January, 2018

msyaukat left a reply on Redirect With 2 Ids • 6 days ago

what does this mean?

Missing argument 3 for App\Http\Controllers\CompanyBranchController::update()

msyaukat left a reply on Edit & Update Route Problem • 6 days ago

@tisuchi

why does it says :

Missing argument 3 for App\Http\Controllers\CompanyBranchController::update()

msyaukat started a new conversation Redirect With 2 Ids • 6 days ago

how do I redirect after updating when my show has 2 ids: company_id and company_branch_id.

route:

Route::get('company/{company_id}/companybranch/{company_branch_id}', ['uses' => '[email protected]', 'as' => 'companybranch.show']);

controller of update:

public function update(Request $request, $company_branch_id)
    {
        $company = Company::find($company_id);
        $companybranch = CompanyBranch::find($company_branch_id);

//didn't include this

 return redirect()->route('companybranch.show', $company->company_id, $companybranch->company_branch_id);

msyaukat left a reply on Edit & Update Route Problem • 6 days ago

okay updating is done. now how do I redirect after updating and grab company_id and company_branch_id?

controller:

return redirect()->route('companybranch.show', $company->company_id, $companybranch->company_branch_id);

route for show:

Route::get('company/{company_id}/companybranch/{company_branch_id}', ['uses' => '[email protected]', 'as' => 'companybranch.show']);

10th January, 2018

msyaukat started a new conversation Edit & Update Route Problem • 1 week ago

I'm trying to execute an edit a COMPANY BRANCH which is related to a COMPANY. I'm stuck on how to update because I'm dealing with 2 keys for the route: company_id and company_branch_id.

Route:

Route::get('company/{company}/companybranch/{companybranch}/edit', ['uses' =>'[email protected]', 'as' => 'companybranch.edit']);

Route::post('company/{company}/companybranch/{companybranch}', ['uses' => '[email protected]', 'as' => 'companybranch.update']);

Form:

<form class="form-horizontal" role="form" method="POST" action="{{ route('companybranch.update', $company->company_id, $companybranch->company_branch_id) }}" enctype="multipart/form-data">
{{ csrf_field() }}

Controller:

public function edit($company_id, $companybranch_id)
    {
        $company = Company::find($company_id);
        $companybranch = CompanyBranch::find($companybranch_id);

public function update(Request $request, $company_id, $companybranch_id)
    {
        $company = Company::find($company_id);
        $companybranch = CompanyBranch::find($company_branch_id);

16th November, 2017

msyaukat left a reply on Is It Possible To Put @section In Conditional(IF)? • 2 months ago

@tisuchi actually, this is not working.

9th November, 2017

msyaukat started a new conversation HasOne Query Existence. • 2 months ago

how do I query hasOne existence? What I want to achieve is, if the user has not register their company's contact, Add Company Contact will appear.

this is my attempt:

controller

$companyContact = Company::find($id)->companycontact()->get();

view

@if($companyContact->isEmpty())
     <p><a href="#">Add Company Contact</a><p>
@endif

3rd November, 2017

msyaukat started a new conversation Should I Use HasManyThrough Here? • 2 months ago

This is my database:

User
-id

Company
-company_id
-user_id
-company_name

Company's Contact
-company_contact_id
-company_id
-company_address

Now, I want to query whether a user's company has added company contact. Having read the HasManyThrough relationship, it somehow says that I need to add a user_id key in the Company Contact table. Is that right?

because if that's right, later on if I want to add Company Branches, then it'll have multiple level of relationship.

1st November, 2017

msyaukat left a reply on Query: Authenticated User's Post's Comment. • 2 months ago

@mdecooman I have yet to learn this. no wonder. thanks mate

msyaukat started a new conversation Query: Authenticated User's Post's Comment. • 2 months ago

I know how to find the existence of Authenticated User's Post and Post's Comments using has. But, how do I find the existence of Authenticated User's Post's Comments?

$userComment  = Auth::user()->Post::has('comments')->get();

is this logical?

31st October, 2017

msyaukat left a reply on Relationship Conditionals (IF) For Post's Comments. How To? • 2 months ago

$posts = App\Post::has('comments')->get();

is supposed to call for a collection right? Now, why if there's no comment for a post and I query:

@if($post->isEmpty())
   
@endif 

it still says that it has a comment? the column for the particular post is empty. So, isEmpty should be the query right?

msyaukat started a new conversation Is It Possible To Put @section In Conditional(IF)? • 2 months ago

I'm using Google Map in my project. It requires a script which I include in a section: @section('script) . I want it to only load if one collection is empty:

@if($map->isEmpty())
    
@endif 

How do I wrap the section in the conditional?

msyaukat started a new conversation Relationship Conditionals (IF) For Post's Comments. How To? • 2 months ago

How do I implement an "IF" statement for relationship? mine is not working:

@if($post->comments->isNotEmpty())
    <p><a href="#">Add Comments</a><p>
@endif 

25th October, 2017

msyaukat started a new conversation Problems With Phpunit(testing) • 2 months ago

I am learning a lesson. I can't execute phpunit. Here's what it says:

     PHP Fatal error:  Call to undefined method PHPUnit_Util_Configuration::getTestdoxGroupConfiguration() in C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\TextUI\TestRunner.php on line 1066

Fatal error: Call to undefined method PHPUnit_Util_Configuration::getTestdoxGroupConfiguration() in C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\TextUI\TestRunner.php on line 1066

23rd October, 2017

msyaukat left a reply on Authenticated User Checked, But Problem With Guest. • 2 months ago

@tykus thanks a lot. I'll be more specific next time.

msyaukat started a new conversation Authenticated User Checked, But Problem With Guess. • 2 months ago

I've checked the authenticated user, now if I'm a guess it says something is missing. Why does this happen? I've used "IF".

@if($company->user->id == Auth::user()->id)
     <p><a href"#">Edit Post</a></p>
@endif 

Why should there be a problem for guess?

19th October, 2017

msyaukat left a reply on If $post Is Authenticated User's Post? • 2 months ago

@druc I've started with Laravel 5.2. This is new. Which lesson on Laracasts teaches this(Authorization)?

16th October, 2017

msyaukat left a reply on If $post Is Authenticated User's Post? • 3 months ago

@PawelMysior now it won't work with guest(non-authenticated user). do I need to use auth::check?

msyaukat left a reply on If $post Is Authenticated User's Post? • 3 months ago

@PawelMysior so I just need to change it to == ?

msyaukat started a new conversation If $post Is Authenticated User's Post? • 3 months ago

How do I check if $post is Authenticated User's post? Which method should I use? There's no "isEqual".

@if({{$post->post_id}} = Auth::user()->posts->post_id)
                  Edit Post
                @endif

12th October, 2017

msyaukat left a reply on If Authenticated User Has Post? • 3 months ago

thanks a lot guys. @tykus and @tisuchi . I am new in programming. Sorry if I annoy you guys with my unending question. Is it wrong to ask so many questions here?

msyaukat started a new conversation If Authenticated User Has Post? • 3 months ago

I want to load if authenticated user has post load something, if authenticated user has not load something else. This is my attempt:

            @foreach($posts as $post)
                    
                    @if(collect([$post])->isEmpty());
                        <p>Add a post</p>
                    @else
                        {{ $post->post_title }}

                    @endforeach 

where did I do wrong?

11th October, 2017

msyaukat left a reply on How To Query Authenticated User's Post? • 3 months ago

@Vable thanks a lot man.

msyaukat left a reply on How To Query Authenticated User's Post? • 3 months ago

@Vable

so in the view, I just have to write:

@foreach($posts as $post)
{{ $post->post_title }}
@endforeach 

to retrieve the post's title

is this correct?

msyaukat left a reply on How To Query Authenticated User's Post? • 3 months ago

@Vable

if I use

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

it will grab the user which id I inserted. I want to grab the user that is authenticated/currently logged in.

msyaukat started a new conversation How To Query Authenticated User's Post? • 3 months ago

How do I retrieve authenticated user's post? I have done all the relationship.

6th October, 2017

msyaukat left a reply on Why Am I Querying 2 Items When I'm Only Querying One? • 3 months ago

LessonFilters is working perfectly. The thing is, everytime I just want query Options(Categories), it failed because the text search is blank. Should I try to use ifempty?

2nd October, 2017

msyaukat left a reply on Why Am I Querying 2 Items When I'm Only Querying One? • 3 months ago

@tisuchi

view form:

                        {{ csrf_field() }}

                         {{-- Search Form --}}
                        <div class="form-group">
                            
                            {{-- Company Text Search --}}
                            <div class="col-md-6">
                                <input type="search" class="form-control" name="company_name" placeholder="Search" rows="4">
                            </div>

                            {{-- company main category --}}  

                            <select class="form-control select2-multi" name="company_maincategory" multiple="multiple" style="width: 344px" data-placeholder="select main category">
                              @foreach($categories as $category)
                                <option value='{{ $category->main_cat_name }}'>{{ $category->main_cat_name }}</option>
                               @endforeach
                            </select>
                            
                            {{-- company sub category --}}  

                            <select class="form-control select2-multi2" name="company_subcategory" multiple="multiple" style="width: 344px" data-placeholder="select sub category">
                              @foreach($subcategories as $subcategory)
                                <option value='{{ $subcategory->sub_cat_name }}'>{{ $subcategory->sub_cat_name }}</option>
                               @endforeach
                            </select>

                        </div>                        

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    Search
                                </button>
                            </div>
                        </div>

                    </form>

controller:

public function filtersearch(LessonFilters $filters)
    {
        $categories = MainCategory::all();
        $subcategories = SubCategory::all();
        $companies = Company::all();

        $filters = Company::filter($filters)->get();

        return view('advancedsearch')->with('companies', $companies)->with('categories', $categories)->with('subcategories', $subcategories)->with('filters', $filters);
    }

msyaukat started a new conversation Why Am I Querying 2 Items When I'm Only Querying One? • 3 months ago

I have a query form of Company Name and Company Category. I can query Company Name. But I can't just query(filter) Company Category alone as it would also query Company Name which I leave blank that leads to an error of 'missing argument'.

What's the problem?

21st September, 2017

msyaukat left a reply on How Do I Return A View? • 3 months ago

@Goldoni I want to return the filter in the view. how do I combine the filter in the "return view"?

msyaukat left a reply on How Do I Return A View? • 3 months ago

@Snapey no. it's not a trick question. the 'comment' is if I want to return the view. now, I want to return the view with the filters. how do I implement it?

msyaukat started a new conversation How Do I Return A View? • 3 months ago

In the lesson I learn to return a JSON. Now, How do I return a view for this filter?

public function filtersearch(LessonFilters $filters)
    {
        $categories = MainCategory::all();
        $subcategories = SubCategory::all();
        $companies = Company::all();

        return Company::filter($filters)->get();

        // return view('advancedsearch')->with('companies', $companies)->with('categories', $categories)->with('subcategories', $subcategories);
    }

19th September, 2017

msyaukat left a reply on How Do I Put A Variable Here? • 3 months ago

so, if I want to use $request, I just need to put it in a function closure just like what you did there eh. Thanks!

msyaukat started a new conversation How Do I Put A Variable Here? • 3 months ago

How do I put a variable in my query here:

<?php

namespace App;
use Illuminate\Http\Request;


class LessonFilters extends QueryFilter
{

    public function name($search) 
    {
        return $this->builder->where('company_name', 'LIKE', "%$search%")->orWhere('company_description', 'LIKE', "%$search%");
    }

    public function maincategory()
    {
        return $this->builder->whereHas('maincategories', function ($query) {
            $query->where('main_cat_name', 'Fashion Man'); // <--- how do I put make this string here(Fashion Man) to be a variable? I can't seem to use $request
        });
    }
}

I'm practicing a lesson from https://laracasts.com/series/eloquent-techniques/episodes/4. I

7th September, 2017

msyaukat started a new conversation Dedicated Query String Filtering • 4 months ago

I am attempting to create a filter search function from https://laracasts.com/series/eloquent-techniques/episodes/4. I am able to filter names, but I have difficulties in querying many to many relationship here as it uses 'builder' and 'class'.

how do I filter my 'maincategories' here:

public function name($search) // company?name
    {
        return $this->builder->where('company_name', 'LIKE', "%$search%")->orWhere('company_description', 'LIKE', "%$search%");
    }

    public function maincategory(Request $request)
    {
        $companyMainCat = $request->get('main_cat_name');

        return $this->builder->whereHas('maincategories', function ($query) {
            $query->where('main_cat_name', $companyMainCat);
        }); // here's my attempt
    }

22nd August, 2017

msyaukat started a new conversation Filtering Many To Many • 4 months ago

in this lesson: https://laracasts.com/series/eloquent-techniques/episodes/4 , I learn how to query filter. However, I don't know how to filter many to many relationship. In the document, it teaches me to use "whereHas" (https://laravel.com/docs/5.4/eloquent-relationships#querying-relationship-existence), but I can't use it in mine. It says "Method does not exist"

Here's my code, the problem is in the second "if":

public function searchtest(Request $request)
    {
        $company = (new Company)->newQuery();
        $companyName = $request->get('company_name');
        $companyMainCat = $request->get('main_cat_name');

        if ($request->has('company_name')) {
            $company->where('company_name', 'LIKE', "%$companyName%");
        }
    //here's the problem
        if ($request->whereHas('maincategories', function ($q) {
            $q->$company->where('main_cat_name', $companyMainCat);
        }))

        return $company->get();
    }

15th August, 2017

msyaukat left a reply on Many To Many Query • 5 months ago

thanks a lot guys. I will try this. I have no idea what to search for in the documentation.

14th August, 2017

msyaukat started a new conversation Many To Many Query • 5 months ago

I have Company and each of them would be assigned with Categories (many to many).

How do I query the company based on the specific Categories.

In Laracasts, I have only learned this:

public function searchtest(Request $request)
    {          
    return Company::with('categories')->has('categories')->get();
    }

This only return companies that has categories. How do I query company that has a category of Electronics or Education?

one more thing. I need to learn some advanced search function that can do filters of varying relationships. can someone lead me to a tutorial? thanks

Edit Your Profile
Update

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