phpmaven

phpmaven

Member Since 1 Year Ago

Experience Points 16,600
Experience Level 4

3,400 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 154
Lessons
Completed
Best Reply Awards 1
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

11 Jul
1 week ago

phpmaven left a reply on Add Rows To Database Collection

Yes, thank you. That's exactly what I want.

phpmaven left a reply on Add Rows To Database Collection

That works great! Thank you so much!

phpmaven left a reply on Add Rows To Database Collection

I just want to add items (rows) to the collection. So if I get 8 rows in the collection, I want be able to manually add more rows.

phpmaven started a new conversation Add Rows To Database Collection

I'm creating a collection using the following code:

                    $attributes = DB::table('product_attribs')
                    ->where('Attrib_SKU', '=', $request->query('SKU'))
                    ->orderBy('Attrib_Seq', 'asc')
                    ->get();

I'm trying to figure out how to add additional rows to the collection.

I tried doing this, but it ends up adding arrays to the collection:

                    $attributes->push([
                    'Attrib_SKU'=>  'ichhar', 
                    'Attrib_Seq'=>  'uploads/pub.jpg',
                    'Attrib_Standard'=> '',
                    'Attrib_Name'=> '',
                    'Attrib_Type'=> '',
                    'Attrib_Size'=> '',
                    'Attrib_Initial_Value'=> '',
                    'Attrib_Supress'=> '',
                    'Attrib_Label'=> '',
                    'Attrib_Required'=> '',
                    'Attrib_Value'=> '',
                    'Attrib_Valid_Type'=> '',
                    'Attrib_Valid_Msg'=> '',
                    'Attrib_Dependency'=> '',
                    'OridinalLabel'=> '' ]);

In C# for example I would create a new object based on the product_attribs model and add that to the collection. Is there a way to do something similar in Laravel?

Thanks

10 Jun
1 month ago

phpmaven left a reply on Iterating Collection

Thank you for you replies. What is interesting is that it does actually save the values to the collection with the syntax I had and you can read them, you just can't iterate it. In my case the syntax that works is:

$testCollection= collect();

$testCollection->push('TestValue1', 'test1');
$testCollection->push('TestValue2', 'test2');
$testCollection->push('TestValue3', 'test3');
$testCollection->push('TestValue4', 'test4');

foreach ($testCollection $key => $value) {
    echo $key;
}

phpmaven started a new conversation Iterating Collection

I'm using a collection to save form input values, like this:

$testCollection= collect();

$testCollection->TestValue1 = "test1"
$testCollection->TestValue2 = "test2"
$testCollection->TestValue3 = "test3"
$testCollection->TestValue4 = "test4"

I'm trying to figure out how to iterate the collection to see all of the properties and their values. I've tried using a foreach loop and that doesn't work. It just treats it like it's an empty collection.

Thanks

07 Jan
6 months ago

phpmaven left a reply on Redirect::back()->withInput(Input::all()); Not Working

Well, I'm not getting that far. It's hitting the:

        {
            return Redirect::back()->withInput(Input::all());
        }

in the controller and redirecting back to the calling form. If it passes validation then it will hit this code:

        {
            $cartMessage = "Quantity of item was updated in your cart!";
            return view('display-cart', compact('title', 'cartMessage', 'optionTotal', 'product'));
        }
        else 
        {
            $cartMessage = "Item was added to your cart!";
            return view('display-cart', compact('title', 'cartMessage', 'optionTotal', 'product'));
        }

phpmaven left a reply on Redirect::back()->withInput(Input::all()); Not Working

When I hit this code in my controller:

        {
            return Redirect::back()->withInput(Input::all());
        }

Input::all() has all of the data from the inputs there. It just is getting hammered somewhere when it gets redirected back to the posting page. If I dump the session on the redirected page _flash is empty and old is an empty array

phpmaven left a reply on Redirect::back()->withInput(Input::all()); Not Working

@REALRANDYALLEN - When the form posts, it hits this route:

Route::post('/display-cart.html', '[email protected]');

Controller:

 public function add(Request $request) {

        $product = DB::table('products')->where('SKU', $request->SKU)->first();

        $productAttributes = DB::table('product_attribs')->where('Attrib_SKU', $request->SKU)->get();

        $rules = [];

        $rules['Main_Quantity'] = 'required|numeric|min:'.$product->Min_Quant;   

        foreach ($productAttributes as $productAttribute) {
            if ($productAttribute->Attrib_Required == "Yes") {
                if ($productAttribute->Attrib_Type == "Input") {
                    $rules[$productAttribute->Attrib_Name] = 'required|max:'.$productAttribute->Attrib_Size;           
                } elseif ($productAttribute->Attrib_Type == "List") {
                    $rules[$productAttribute->Attrib_Name] = 'required'; 
                }
            }
        }

        $validator = Validator::make($request->all(), $rules);

        if($validator->fails())
        {
            return Redirect::back()->withInput(Input::all());
        }

        if ($product != null) 
        {
            $alreadyInCart = Cart::search(function ($cartItem, $rowId) use ($request) {
                return $cartItem->id === $request->id;
            });

            $item = Cart::search(function ($cart, $key) use($request) {
                return $cart->id == $request->SKU;
             })->first();
            
            if($item != null && $item->qty > 0) 
            {
                $quantity = $item->qty + $request->Main_Quantity;
            }
            else
            {
                $quantity = $request->Main_Quantity;
            }
             
            $price = $this->getProductPrice($product, $quantity);

            $options = [];

            $optionTotal = 0;

            foreach ($productAttributes as $productAttribute) {
                {
                    if ($request->{$productAttribute->Attrib_Name} > "")
                    {
                        // if the option value has a SKU in brackets, I.E. "White[PRD-001]", it's an additional charge for that chosen option
                        if (preg_match('#\[(.*?)\]#', $request->{$productAttribute->Attrib_Name}, $match))
                        {
                            $attributeProduct = DB::table('products')->where('SKU', $match[1])->first();
                            if ($attributeProduct != null)
                            {
                                $options[$productAttribute->Attrib_Name] = preg_replace('`\[[^\]]*\]`', '', $request->{$productAttribute->Attrib_Name});
                                $options[$productAttribute->Attrib_Name."&Price"] = $attributeProduct->Price;
                                $options[$productAttribute->Attrib_Name."&Quantity"] = $quantity;
                                $options[$productAttribute->Attrib_Name."&TotalPrice"] = $quantity * $attributeProduct->Price;
                            }
                        }
                        else 
                        {
                            $options[$productAttribute->Attrib_Name] = $request->{$productAttribute->Attrib_Name};
                        }
                    }
                }
            }

            $optionTotal = $this->getTotalAttributeCost();  

            Cart::add(['id' => $request->SKU, 'name' => $product->Description2, 'qty' => $request->Main_Quantity, 'price' => $price, 'options' => $options])->setTaxRate(0);
        }   
        
        $title = "Shopping Cart";
      
        if ($alreadyInCart)
        {
            $cartMessage = "Quantity of item was updated in your cart!";
            return view('display-cart', compact('title', 'cartMessage', 'optionTotal', 'product'));
        }
        else 
        {
            $cartMessage = "Item was added to your cart!";
            return view('display-cart', compact('title', 'cartMessage', 'optionTotal', 'product'));
        }
    }

phpmaven left a reply on Redirect::back()->withInput(Input::all()); Not Working

Route:

Route::get('/{parameter1}/{parameter2}.html', '[email protected]');

Controller:

    public function show($parameter1, $parameter2)
    {
        //dd(Session::all());

        // lookup parameters to see if we have a matching product in products
        $product = DB::table('products')->where('SKU', $parameter2)
            ->first();

        if ($product == null) {
            // if it doesn't match the SKU, then append .html to it and see if we match a Page_Name
            $parameter2 = $parameter2.".html";
            $product = DB::table('products')
                ->where('Page_Name', $parameter2)
                ->first();
            }

        if ($product == null) {
            return "Product was not found!";
        }

        // add the current product SKU and url to the session so that we can track the visited products

        $visitedProducts = $this->addProductToSessionArray(Request::fullUrl(), $product);

        $title = $product->Description;

        $productImages = $this->getProductImages($product);

        $productPrices = $this->getProductPrices($product);

        $productAttributes = DB::table('product_attribs')->where('Attrib_SKU', $product->SKU)->get();

        $relatedProducts = DB::table('related_products')
            ->join('products', 'SKU', '=', 'related_products.Related_SKU')
            ->where('Main_SKU', $product->SKU)
            ->get();

        $productMessages = collect();

        if ($product->Mult_Quant > 1)
        {
            $productMessages->push("Must be ordered in multiples of ".$product->Mult_Quant);
        }

        if ($product->Min_Quant > 1)
        {
            $productMessages->push("Must order a miminum of ".$product->Min_Quant);
        }
        
        if (Request::has('gps'))
        {
            if ($product->Min_Quant > 1)
            {
                if ($productPrices->max('Price') > 0)
                {
                    $productMessages->push("Minimum of ".$product->Min_Quant." = $".number_format((float)$productPrices->max('Price'), 2, '.', ''));
                }
                else 
                {
                    $productMessages->push("Minimum of ".$product->Min_Quant." = $".number_format((float)$product->Price, 2, '.', ''));
                }
            }              
        }

        if ($product->Set_Quant)
        {
            if ($productPrices->where('Price', '>', 0)->min('Price') > 0)
            {               
                $priceMessage = "(as low as $".number_format((float)$productPrices->where('Price', '>', 0)->min('Price'), 2, '.', '')." each)";
            }
            else 
            {             
                $priceMessage = "(as low as $".number_format((float)$product->Price, 2, '.', '')." each)";
            }
        }      

        $stores = MenuFunctions::getStores();
        $headings = MenuFunctions::getHeadings();
        $menus = MenuFunctions::getMenus();

        return view('productDetailsView', compact('title', 'productMessages', 'priceMessage', 'product', 'productImages', 'productAttributes', 'productImages', 'productPrices', 'relatedProducts', 'visitedProducts', 'stores', 'headings', 'menus'));
    }

View:

@extends('layouts.master')
@section('content')
<script type="text/javascript">
var pr_style_sheet="/css/reviews.css";
function show_reviews() {
    $('li#p_reviews').addClass('current').siblings().removeClass('current').parents('div.section').find('div.box').hide().end().find('div.box:eq('+ 1 +')').fadeIn(150);
    location.href = "#ReviewHeader";    
}
<?php
//dd(old('Main_Line_1'));
?>
</script>
<script type="text/javascript" src="http://cdn.powerreviews.com/repos/13098/pr/pwr/engine/js/full.js"></script>
<div class="container">
    <div class="row">
        <div class="col-md-12 text-center">
        <h3>{!! $product->Description !!}</h3>
        </div>
    </div>
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="#">Home</a></li>
            <li class="breadcrumb-item"><a href="#">Library</a></li>
            <li class="breadcrumb-item active" aria-current="page">Data</li>
        </ol>
    </nav>
    <div class="row">
        <div class="col-12 col-lg-6">
            <div class="card bg-light mb-3">
                <div class="card-body">
                    @include('partials.productImages')
                    {!! $product->Detail_Desc  !!}
                </div>
            </div>
        </div>
        <div class="col-12 col-lg-6 add_to_cart_block">
            <div class="card bg-light mb-3">
                <div id="product-div" class="card-body">
                    <form name="product_form" id="product_form" method="post" action="/display-cart.html">
                        @include('partials.productPricing')
                        {{ csrf_field() }}
                        <input type="hidden" name="SKU" id="SKU" value="{{$product->SKU}}">
                        @includeWhen($product->Person_Addon == "fc_glass_designs2", 'partials.productDesigner')
                        @include('partials.productAttributes')
                    </form>
                    <div class="pr_snippet_product">
                        <script type="text/javascript">
                            POWERREVIEWS.display.snippet(document, { pr_page_id : "{{ $product->SKU  }}", pr_read_review : "javascript:show_reviews();"});
                            </script>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
   
@endsection

phpmaven left a reply on Redirect::back()->withInput(Input::all()); Not Working

@REALRANDYALLEN - I did see this when I was searching for an answer, but I don't really understand what you mean. I have a route setup in web.php for the page that has the form that I'm posting and validating and redirecting back to.

phpmaven left a reply on Redirect::back()->withInput(Input::all()); Not Working

@SNAPEY - Yes dd(Input::all()) and I see all of the input data

phpmaven started a new conversation Redirect::back()->withInput(Input::all()); Not Working

I'm doing form validation and I'm doing the following:

     if($validator->fails())
    {
        return Redirect::back()->withInput(Input::all());
    }

But on the page I'm redirecting back to if I try to use old('form_input_name') it's always null.

This is version 5.6.6

Thanks

19 Dec
7 months ago

phpmaven left a reply on Iterate Over A Grouped Collection

I guess I was overthinking it. This works.

    foreach ($grouped  as $group)
    {
        foreach ($group $menu)
        {
            echo $menu->Item_Title;
        }
    }

phpmaven started a new conversation Iterate Over A Grouped Collection

I'm creating a grouped collection like this:

$grouped = $menus->groupBy('Store');

$menus is a collection I retrieved from the database.

There are 4 different groups "Wedding", "Baby, "All", "Cruise"

So $grouped has 4 nested collections that seem to be called the same name as the groups.

How can I iterate over $grouped an the nested collections within it?

I need to do this both in a controller and in a Blade template.

I tried to do something like this, but I get it to work:

    foreach ($grouped as $group)
    {
        foreach ($group->Wedding as $menus)
        {
            foreach ($menus as $menu) {
               echo $menu->Item_Title;
            }
        }
    }

Thanks,

Mark

29 Nov
7 months ago

phpmaven started a new conversation Running Code Outside Of Public Folder

I have several cron jobs that run on my Linux box and the php files that run are outside of my public folder as I don't want these files to be able to be accessed publicly. Is there a way I can use Laravel in these php files even though the don't get routed through index.php? I'de like to be able to use the query builder as well as other Laravel goodies. Thx.

26 Mar
1 year ago

phpmaven left a reply on Pass An Array Of Url Parameters To Controller

@lostdreamer_nl Thank you so much for pointing me in the right direction. This is what I ended up with and it works great.

Route::get('/{parameter}-{page}.html', function ($parameter, $page) {
   $controller = \App()->make('\App\Http\Controllers\ListingController');
   $parameterArray = array();
   array_push($parameterArray, $parameter);
   array_push($paraparameterArraymeters, $page);
   return $controller->callAction('Show', $parameterArray);
})->where('parameter', '.*')->where('page','^[0-9]+');

phpmaven left a reply on Pass An Array Of Url Parameters To Controller

It's not a problem. I was just curious. Thanks for your help.

phpmaven left a reply on Pass An Array Of Url Parameters To Controller

I'm trying to match the following 4 url scenarios:

text-1.html
text-text-1.html
text-text-text-1.html
text-text-text-text-1.html

If I only have one route:

Route::get('/{parameter1}-{parameter2}-{parameter3}-{parameter4}-{page}.html', '[email protected]')->where('page','^[0-9]+');

Then it will only match the last url.

phpmaven left a reply on Pass An Array Of Url Parameters To Controller

Yes, I'm aware of using optional parameters, however that doesn't solve my problem.

I have the following 4 routes defined:

Route::get('/{parameter1}-{parameter2}-{parameter3}-{page}.html', '[email protected]')->where('page','^[0-9]+');
Route::get('/{parameter1}-{parameter2}-{page}.html', '[email protected]')->where('page','^[0-9]+');
Route::get('/{parameter1}-{page}.html', '[email protected]')->where('page','^[0-9]+'

If I send those all to the same "Show" method:

public function show( $parameter1 = null,  $parameter2 = null,  $parameter3 = null,  $parameter4 = null, page = null)

I get a "Too few arguments to function App\Http\Controllers\ListingController::show()" on all Routes except the first one.

phpmaven left a reply on Pass An Array Of Url Parameters To Controller

Thanks, but that would match every single url coming in. What I'm looking for is something like this:

Route::get('/{parameter1}-{parameter2}-{parameter3}-{parameter4}-{page}.html', function () {
        $parameters = $parameter1."-".$parameter2."-".$parameter3."-".$parameter4;
    // call [email protected] and pass $parameters to it.
});

Then I could do something like you suggest in the controller.

25 Mar
1 year ago

phpmaven started a new conversation Pass An Array Of Url Paramaters To Controller

I'm trying to figure out how to turn the parameters in the url I'm trying to match and pass them as an array to my controller.

I have the following routes defined:

Route::get('/{parameter1}-{parameter2}-{parameter3}-{parameter4}-{page}.html', '[email protected]);
Route::get('/{parameter1}-{parameter2}-{parameter3}-{page}.html', '[email protected]);
Route::get('/{parameter1}-{parameter2}-{page}.html', '[email protected]);
Route::get('/{parameter1}-{page}.html', '[email protected]);

I would like to pass all of the parameters to the Show method as one array so that I can have just one "Show" method in the controller handle all 4 of these scenarios. I looked at making the parameters optional, but I couldn't see how to do that and still match the urls properly. If I could pass one array to a single "show" method, then I could just iterate the array and handle further processing depending on which parameters had values.

Hopefully that makes sense.

Thanks

24 Mar
1 year ago

phpmaven left a reply on Skepticism

I'm a newbie myself and have gone though most of Jeffrey's videos, and I totally agree with you. Working on my first Laravel project and I'm really impressed with the framework so far.

phpmaven left a reply on Regex On Route

Ok, I do apologize. Being a newbie I didn't really understand how routing works. I did some more testing and realized the following: If you have more than one route defined with the same url matching pattern and with the same parameter names, it will use the last one that matches:

// ignored
Route::get('/{param1}-{param2}.html', '[email protected]')->where('param2','^index');
// get executed
Route::get('/{param1}-{param2}.html', '[email protected]');

If the parameter names are different however, it will match the first route and ignore any other routes that may match the same url pattern:

// gets executed
Route::get('/{param1}-{param2}.html', '[email protected]')->where('param2','^index');
// ignored
Route::get('/{param3}-{param4}.html', '[email protected]')

Now it makes perfect sense.

phpmaven left a reply on Regex On Route

Thank you.

I'm a Laravel newbie and I'm used to handling routing with Apache rewrite rules and I was trying to figure out some way to basically say: "Once a route matches a url pattern, stop matching any more routes in web.php". It seems that this isn't possible.

What I will end up doing is something similar to what you suggested but redirect to another controller which is already defined in web.php:

public function show($category, $pagename) {
    if (preg_match('/^(\d+|p-\S+|index)$/', $pagename, $matches)) {
    return redirect()->action('[email protected]');
    }

    // continue normal processing
}
23 Mar
1 year ago

phpmaven started a new conversation Regex On Route

I'm trying to figure out how to route pages that DON'T match a certain pattern. I have 3 different values that I want to test and make sure are not present in part of the incoming URL.

Route::get('/{category}/{pagename}.html', '[email protected]')->where('pagename','regex-pattern');

If pagename is not all numbers and it doesn't start with "p-" and it doesn't start with "index", I want to match it.

I can't figure out how to setup the regex to match this. Maybe there is a better way to try to do this.

Thanks

22 Feb
1 year ago

phpmaven left a reply on Like Operator Doesn't Work

Ah you can do $collection->contains('product', 'Bookcase');

Great

phpmaven left a reply on Like Operator Doesn't Work

Doh! There IS a contains method. LOL

phpmaven left a reply on Like Operator Doesn't Work

Thanks for the replies. This is more of general question about how these Eloquent collections work more than something I would actually use in a real world scenario.

I'm brand new to Laravel and just going through the training videos and trying to come up to speed. I'm a long time PHP developer and have also been heavily involved with C# the last year or so.

I'm used to using linq query syntax and was just wondering how it works on collections in Laravel. I guess I was expecting something like $resellers->contains("duck"). With linq is C#, it's amazing what you can with collections.

Quite impressed with Laravel so far. I'm planning on using it on my next project.

I appreciate the quick responses. Seems like a pretty "lively" community.

Mark

phpmaven started a new conversation Like Operator Doesn't Work

I have the following code in my controller:

    $resellers = Resellers::all();
    $string = "Duck";
    $results =  $resellers->where('Contact_Name', 'like', '%'.$string.'%');

I have 2 records with the names: "Donald Duck" and "Daisy Duck"

$results will come up with no results.

If I change the code to this:

    $resellers = Resellers::all();
    $string = "Donald Duck";
    $results =  $resellers->where('Contact_Name', 'like', $string);

I get 1 result back.

It seems that the "like" operator is working like "=" and is ignoring the beginning and ending "%"

If I don't use Eloquent and just use the query builder, it works fine:

    $string = "Duck";

    $results = Resellers::where('Contact_Name', 'like', '%'.$string.'%')->get();

Are you not able to use the "like" operator like this on Eloquent objects or am I missing something?

Thanks,

Mark