kapitan

Experience

710

0 Best Reply Awards

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

11th July, 2018

kapitan left a reply on Custom Pagination Name Using Repository Pattern • 1 week ago

didnt use repository pattern, just used Model::paginate(5,['*'],'page_red')

kapitan left a reply on Eloquent • 1 week ago

thank you xmarks, i just added groupBy on your answer and removed the ->limit

6th July, 2018

kapitan left a reply on Trying To Make A Query-of-query • 2 weeks ago

i got it working now.

what i did was put the main query:

$orders = Item::where('destination_id', '1,2,3')->orWhere('color_id', '1,2');

on a separate method :

private function orderMain() { $orders = Item::where('destination_id', '1,2,3')->orWhere('color_id', '1,2');

    return $orders;
}   

then just have reference my blue and red order variables like these:

$blue_orders = $this->orderMain();

$red_orders = $this->orderMain();

thank you so much on your time sir BishoyWagih!

kapitan left a reply on Trying To Make A Query-of-query • 2 weeks ago

sad, it looks like the $orders had became synonymous with $blue_orders as soon as the $blue_orders uses the $orders.

that's why when i tried to $dump($orders); again, the query on the $blue_orders is carried.

any other ideas?

kapitan left a reply on Trying To Make A Query-of-query • 2 weeks ago

ahahahaaa! i literally laughed when i saw your answer. but of course! ill try this right now. ill get back right after testing. but i am already embarrassed.

kapitan left a reply on Trying To Make A Query-of-query • 2 weeks ago

have i done what you need sir?

kapitan started a new conversation Trying To Make A Query-of-query • 2 weeks ago

My goal is to minimize the roundtrip to the database that's why I have been trying to optimize a query and trying to make a query-of-query.

I have this :

$orders = Item::where('destination_id', '1,2,3')->orWhere('color_id', '1,2');

$blue_orders = $orders;

if($request->input('blue_order_destination')) $blue_orders = $blue_orders ->where('destination_id', $request->input('blue_order_destination'));

//dump($orders);

$blue_orders = $order_blue->where('color_id', 1)->get();

$red_orders= $orders;

if($request->input('red_order_destination')) $red_orders= $red_orders->where('destination_id', $request->input('red_order_destination'));

$red_orders= $red_orders->where('color_id', 2)->get();

so, i have presented the $blue_orders and $red_orders on a same view file via a separate tabular format.

my problem is that when a user make search on the $blue_orders table per destination ($request->input('blue_order_destination')), the output for $red_orders isn't correct.

when i checked and uncommented the //dump($orders); it appears that the $orders variable had changed and became the same with $blue_orders variable. that is why the output for my $red_orders is incorrect.

this is because there are no "red orders" for that destination, a search parameter that is only intended to be applied for "blue orders".

any thing i am missing here?

29th June, 2018

kapitan left a reply on Eloquent Relationship Three Tables • 3 weeks ago

First, thank you for your reply.

This works if $author returns a single record.

but if $author returns more than one record, it doesn't work.

I have this:

$author = Author::where('name', 'like', '%john%');

am i missing something?

kapitan started a new conversation Eloquent Relationship Three Tables • 3 weeks ago

I have this models with each fields:

Author (id, name)

Post (id, post, author_id)

Comment (id, comment, post_id)

Can you please help me refactor the eloquent statement below for me to search on the User model with the given "name"?

For example, I want to see the comments that are not "okay" from the post's author with the name of "John".

$comments = Comment::where('comment', '!=', 'okay')->get();

thank you very much in advance.

28th June, 2018

kapitan left a reply on Custom Pagination Name Using Repository Pattern • 3 weeks ago

yeah, i tried this:

$order_red = $this->orderRepository->findWhere(['color' => 'red'])->paginate(5,['*'],'pagered');

and it is not working.

sad.

kapitan started a new conversation Custom Pagination Name Using Repository Pattern • 3 weeks ago

I have something like these:

$order_blue = $this->orderRepository->findWhere(['color' => 'blue'])->paginate(5); $order_red = $this->orderRepository->findWhere(['color' => 'red'])->paginate(5);

then i need to display them on the same window / blade on a separate html tables.

my problem is, if I'll click the page 3, the other table also respond.

my second question is, the two tables on display has a search box each, how can i construct the code on my controller to respond on the search boxes individually.

thank you very much in advance!

18th December, 2017

kapitan left a reply on Eloquent • 7 months ago

thank you very much but please kindly consider the new values below of the table:

ID  PARENT_ID   DATE_1  
1   0           01/01/01
2   1           01/02/01
3   1           01/03/01
4   0           01/04/01
5   4           01/05/01
6   4           01/06/01
7   4           01/07/01

kapitan started a new conversation Eloquent • 7 months ago

i have this:

ID PARENT_ID DATE_1 1 0 01/01/01 2 1 01/02/01 3 1 01/03/01 4 0 01/01/01 5 4 01/02/01 6 4 01/03/01 7 4 01/04/01

first, i need to check the records with parent_id not equal to zero, then need to get the latest record based on DATE_1.

results: ID = 3 and 7

pls help

17th December, 2017

kapitan started a new conversation Eloquent Question • 7 months ago

why does the first line works on my die dump, and the second cannot?

1.) $myresult = Registration::find(1); dd($myresult->id);

2.) $myresult = Registration::where('id', 1)->get(); dd($myresult->id);

19th November, 2017

kapitan started a new conversation Parent - Child On The Same Table • 8 months ago

MAIN TABLE

id | parent_id | form_id | is_approved | fruit_id 1 | 0 | 1 | 1 | 1 2 | 1 | 2 | 1 | 2 3 | 0 | 1 | 1 | 3 4 | 3 | 2 | 0 | 4

FRUIT TABLE

id | name 1 | cherry 2 | guava 3 | apple 4 | grapes

by referencing on the Main Table, i need to output all fruit names from the Fruit Table for rows that has a:

1.) parent_id != 0 2.) is_approved=1

how to do this? please help!

11th November, 2017

kapitan left a reply on JS Function's Value Inside Looped Textbox • 8 months ago

got it:

'onkeyup' => 'readonly('.'"item_'.$i.'"'.');'

thanks!

kapitan started a new conversation JS Function's Value Inside Looped Textbox • 8 months ago

how to put the id inside my readonly function inside the loop on my view file?

@foreach ($assets as $asset) @php $i++; @endphp {{ Form::input('text', 'item_'.$i, $asset->item, ['id' => 'item_'.$i, 'placeholder' => 'Item', 'class' => 'form-control input-sm', 'onkeyup' => 'readonly();']) }}

@endforeach

thank you very much!

9th November, 2017

kapitan left a reply on Redirect Page Select Tag Onchange • 8 months ago

i knew now what i have missed, the "/" at the beginning. lesson learned.

kapitan left a reply on Redirect Page Select Tag Onchange • 8 months ago

it works! im sure, im doing this earlier. thank you so much. apologies for bothering you with a basic stuff. take care!

kapitan left a reply on Redirect Page Select Tag Onchange • 8 months ago

thank you, but i tried that but it the:

/register/business/1/edit

only append on my current url which is:

/register/business/create

so it is becomming:

http://localhost:8000/register/business/create/register/business/1/edit

which is an invalid url (page cannot be found)

i only want:

http://localhost:8000/register/business/1/edit

it's really weird.

kapitan started a new conversation Redirect Page Select Tag Onchange • 8 months ago

I have this route:

Route::get('/register/business/{id}/edit', '[email protected]')->name('register.edit.get');

on the home page, i have this select tag:

Form One Form Two Form Three

I need to redirect the page to my route name register.edit.get on the onchange event of my select tag.

please help!!!

5th November, 2017

kapitan left a reply on How To Return Variable From Form Request To Controller • 8 months ago

thank you sir Snapey, im crying, love you dude!

kapitan left a reply on How To Return Variable From Form Request To Controller • 8 months ago

or if you know how to redirect the form inside the App\Http\Requests\MyFormRequests.php to my register.edit.get route name with the myid value on it.

kapitan left a reply on How To Return Variable From Form Request To Controller • 8 months ago

I am saving a record on function persist() on Form Requests.

My goal is to pass the generated id so that I can redirect the page on edit mode for the user. For some reason, the Controller cannot receive the id from Form Requests.

App\Http\Requests\MyFormRequests.php:

function persist() { $business = Business::create([ 'business_name' => $this['business_name'], 'nationality' => $this['nationality'] ]);

return $myid = $business->id; } App\Http\Controllers\MyControllers.php:

public function store(MyFormRequests $request) { $request->persist();

return redirect()->route('register.edit.get', $request->persist()->$myid); }

kapitan started a new conversation How To Return Variable From Form Request To Controller • 8 months ago

How can I return a variable from Form Requests (App\Http\Requests) to Controller (App\Http\Controllers)?

Please help and thank you!

4th November, 2017

kapitan left a reply on Form Request = What Button Was Clicked • 8 months ago

tested and worked.

on saving, the application_form is required.

on updating, i put the value of the file name from database to is_application_form hidden field. so i only require the application_form field if the is_application_form hidden field is empty.

thanks so much!!!

kapitan started a new conversation Form Request = What Button Was Clicked • 8 months ago

I need to know which button was clicked inside a request form on laravel since i have Save and Update buttons.

App\Http\Requests\RegistrationRequest.php

public function rules() { $myrule = [ 'name' => 'required', 'age' => 'required' ];

if (isset($_POST['save']))
{
    $myrule['application_form'] = 'required';
}
elseif (isset($_POST['update']))
{
    $myrule['application_form'] = 'required_without:is_application_form';
}

return $myrule;

} i need to know if the button that was click is Save or Update because I'm requiring for the application_form file field to be required if the Save button is clicked but I only require the application_form field if the is_application_form hidden field is empty.

the setup above is working for name and age field but ignores the codes inside the IF conditions.

the thing is, this is working when placed inside the controller, just above the MyModel::create([]) code.

Edit Your Profile
Update

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