BladeSlayer1000

Experience

590

0 Best Reply Awards

  • Member Since 2 Months Ago
  • 3 Lessons Completed
  • 0 Favorites

18th July, 2017

BladeSlayer1000 left a reply on Duplicated Records With Query • 1 week ago

Indeed, I'm getting a view, but my results are empty. I have some entries in de name field with the name Derk (like Derk J. and Derk V)

BladeSlayer1000 left a reply on Duplicated Records With Query • 1 week ago

I'm getting that. I indeed used it as a way to debug my code. When I log whats comming out of the $orders variable, I receive a array with empty values.

17th July, 2017

BladeSlayer1000 left a reply on Duplicated Records With Query • 1 week ago

@Snapey Yesterday I switched over to eloquent relationships, and now I'm stuck on my query, I have the following:

public function indexnew() {
        Log::info("Called indexnew");

        //Log::debug(Request::get('search'));

        if(isset($_GET['search'])) {
            $searchQuery = $_GET['search'];
        } else {
            $searchQuery = null;
        }

        $orders = Order::whereHas('customers', function($query) use ($searchQuery) {
            $query->where('name', 'LIKE', '%'. $searchQuery .'%');
        })->where('id', 'LIKE', '%'. $searchQuery .'%')->with('customers')->simplePaginate(5);


        Log::debug($orders);
        return view('order.test')->withOrders($orders);
    }

I get a input from $searchquery, and searching on ID works. But when I search for a name like 'Derk' my query fails. I get nothing back, no errors and no result. I tried to use customers.name inside my whereHas but this didnt resolve my issue.

15th July, 2017

BladeSlayer1000 left a reply on Duplicated Records With Query • 1 week ago

$searchQuery can be a name of the customer like 'Dan' or a order id like '1'. It can also be empty.

BladeSlayer1000 left a reply on Duplicated Records With Query • 1 week ago

Some customers has more then one order (like customer 8). And as I look at it, it looks that my Laravel in some way uses the customer id as order id, something I don't understand.. For a look at it here is the part that I use to show the data;

<table class="table table-hover" id="items">
    <thead>
        <tr>
            <th>Bestelnummer</td>
            <th>Naam / bedrijfsnaam</th>
            <th>Telefoonnummer(s)</th>
            <th>Besteld op</th>
            <th>Status</th>
            <th>Acties</th>
        </tr>
    </thead>

    <tbody class="orderRules">
        @foreach($orders as $order)
            <tr>
                <td><a href="{{ route('order.edit', ['id' => $order->id]) }}">#{{ $order->id }}</a></td>
                <td>{{ $order->customers->name }}</td>
                <td>0{{ $order->customers->primaryPhoneNumber }} @php echo (empty($order->customers->secondaryPhoneNumber)) ? '' : '/ 0'. $order->customers->secondaryPhoneNumber @endphp</td>
                <td>{{ date("d-m-Y", strtotime($order->created_at)) }}</td>
                <td>{{ Config::get('settings.deliveryStatus')[$order->orderStatus] }}</td>
                <td>
                    <input type="hidden" value="{{ $order->id }}" class="orderId">
                    <a href="{{ route('order.edit', ['id' => $order->id]) }}" class="btn btn-green glyphicon glyphicon-pencil"></a>
                    <button type="button" id="removeOrderWarning" class="btn btn-green" style="margin-left: 10px;" data-orderId="{{ $order->id }}"><span class="glyphicon glyphicon-trash"></span></button>
                </td>
            </tr>
        @endforeach
    </tbody>
</table>

{{ $orders->appends(['search' => Input::get('search')])->links() }}

BladeSlayer1000 started a new conversation Duplicated Records With Query • 1 week ago

Hi all,

I have the following code:

public function indexnew() {
        Log::info("Called indexnew");

        //Log::debug(Request::get('search'));

        if(isset($_GET['search'])) {
            $searchQuery = $_GET['search'];
        } else {
            $searchQuery = null;
        }

        $orders = Order::where('orders.id', 'LIKE', '%'. $searchQuery .'%')->orWhere('customers.name', 'LIKE', '%'. $searchQuery .'%')->leftJoin('customers', 'customers.id', '=', 'orders.customer_id')->simplePaginate(5);

        Log::debug($orders);
        return view('order.test')->withOrders($orders);
    }

But the problem is that when I run this query, I sometimes get duplicated results back. An example of a duplicated result is the following:

{"current_page":1,"data":[{"id":6,"customer_id":6,"employee_id":0,"orderStatus":0,"paymentMethod":0,"notice":null,"created_at":"2017-06-25 13:06:44","updated_at":"2017-07-14 10:30:14","deleted_at":null,"name":"Jordy Tax","streetname":null,"housenumber":null,"zipcode":null,"cityName":null,"country":null,"primaryPhoneNumber":null,"secondaryPhoneNumber":null,"email":null},{"id":3,"customer_id":3,"employee_id":0,"orderStatus":0,"paymentMethod":0,"notice":null,"created_at":"2017-06-25 13:06:49","updated_at":"2017-07-14 10:46:28","deleted_at":null,"name":"TEst","streetname":null,"housenumber":null,"zipcode":null,"cityName":null,"country":null,"primaryPhoneNumber":null,"secondaryPhoneNumber":null,"email":null},{"id":7,"customer_id":7,"employee_id":0,"orderStatus":0,"paymentMethod":0,"notice":null,"created_at":"2017-06-25 13:06:55","updated_at":"2017-07-14 10:50:47","deleted_at":null,"name":"Gerritsen","streetname":null,"housenumber":null,"zipcode":null,"cityName":null,"country":null,"primaryPhoneNumber":null,"secondaryPhoneNumber":null,"email":null},{"id":8,"customer_id":8,"employee_id":0,"orderStatus":0,"paymentMethod":0,"notice":null,"created_at":"2017-06-25 13:06:59","updated_at":"2017-07-14 10:56:09","deleted_at":null,"name":"Jordy Tax 2","streetname":null,"housenumber":null,"zipcode":null,"cityName":null,"country":null,"primaryPhoneNumber":null,"secondaryPhoneNumber":null,"email":null},{"id":8,"customer_id":8,"employee_id":0,"orderStatus":0,"paymentMethod":0,"notice":null,"created_at":"2017-06-25 13:07:04","updated_at":"2017-07-14 10:56:50","deleted_at":null,"name":"Jordy Tax 2","streetname":null,"housenumber":null,"zipcode":null,"cityName":null,"country":null,"primaryPhoneNumber":null,"secondaryPhoneNumber":null,"email":null}],"from":1,"next_page_url":"http:\/\/intranet.dev\/order\/test?page=2","path":"http:\/\/intranet.dev\/order\/test","per_page":5,"prev_page_url":null,"to":5}  

When I remove the join, my problem gets solved. What's causing this?

BladeSlayer1000 left a reply on Couple Of Questions About Searching • 1 week ago

Quickly after your post I find a solution to my problem. But thanks for your code.

BladeSlayer1000 left a reply on Couple Of Questions About Searching • 1 week ago

I have used that, but then I run into a problem with my pagination. Where it links to the page I'm calling, and thus showing a page without a layout and only results. I can post the code I was using if you want.

BladeSlayer1000 started a new conversation Couple Of Questions About Searching • 1 week ago

Hi All,

I'm currently working on a small order system which needs a search function. Now I was looking at Laravel Scout and I have some questions about it;

  1. Can I use Laravel scout even when the PC isn't connected to the internet?
  2. If I can use Laravel scout offline, which driver do you suggest?
  3. Are there any other possibility's for searching besides Laravel Scout?

13th July, 2017

BladeSlayer1000 left a reply on Temporarily Read A Soft-deleted Record • 1 week ago

Thank you, I totally missed that function.

BladeSlayer1000 started a new conversation Temporarily Read A Soft-deleted Record • 1 week ago

Hello All,

For my website I want to temporarily show a soft-deleted record from my database where users can't change anything (because its sot-deleted). How can I manage this?

19th May, 2017

BladeSlayer1000 left a reply on Validation Gives Htmlentities() Error • 2 months ago

I changed my code as following:

public function store(Request $request)
    {
         //Request all form data
        $unprocessedRequest = $request->all();

        // Validate the form
        Validator::make($request->all(), [
            'customerName' => 'required|unique:customers,name',
            'primaryCellphone' => 'min:10|max:10',
            'zipCode' => 'min:6|max:6',
            'secondaryCellphone' => 'min:10|max:10'
        ])->validate();

It still gives me the same error... And I noticed, the comma after the last value in the array, is this correct or a typo on the wiki?

BladeSlayer1000 started a new conversation Validation Gives Htmlentities() Error • 2 months ago

Hello All,

I have created a store method, with some validation, now it gives me the following error: htmlentities() expects parameter 1 to be string, array given (View: S:\htdocs\resources\views\order\create.blade.php)

Here is a part of my store method;


public function store(Request $request)
    {
        Log::info('Ordercontroller.php;store    Loaded order/store for employee: %username%');

        Log::info('Ordercontroller.php;store    Starting to validate form');
        //Request all form data
        $unprocessedRequest = $request->all();

        // Validate the form
        $validator = Validator::make($unprocessedRequest, [
            'customerName' => 'required|unique:customers,name',
            'primaryCellphone' => 'min:10|max:10',
            'zipCode' => 'min:6|max:6',
            'secondaryCellphone' => 'min:10|max:10'
        ]);

        if($validator->fails()) {
            return Redirect::back()
                ->withErrors($validator) // send back all errors to the login form
                ->withInput();
        }```

As soon as I remove the  if($validator->fails()) { ... } the error disappears. Why am I getting this error?
Edit Your Profile
Update

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