jeudi 29 juin 2017

Laravel Unable to download files in csv format

I get the issue in my code What I want: after clicking on the export button, one CSVfile would be automatic download from the browser.

but it only displays the data in network tab in inspect element but not downloading.

public function Exportcsv(Request $recuestdata) {

 $headers = array(
    "Content-type" => "text/csv",
    "Content-Disposition" => "attachment; filename=file.csv",
    "Pragma" => "no-cache",
    "Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
    "Expires" => "0"
  );

  $filename = "order";
  $output = fopen($filename, 'w+');
  $data=json_decode($recuestdata['row']);

  foreach ($data as $line) {
    fputcsv($output, $line);
  }
  return Response::download($filename, 'order.csv', $headers);
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sq7Sgw
via IFTTT

laravel ajax pass multiple variables to controller?

I need to pass 4 variables to controller so that I can do what I want to do with it, however I get an error:

Missing argument 1 for App\Http\Controllers\ProfileController::getGoogle()

Here's my Controller:

function getGoogle($lat, $lng, $destinationLat, $destinationLng) {
    print_r($lat);
    print_r($lng);
    print_r($destinationLat);
    print_r($destinationLng);
}

and ajax:

function getDirections(lat, lng, destinationLat, destinationLng) {
      $.ajax({
          url: '/google/',
          type: 'post',
          data: { lat: lat, lng: lng, destinationLat: destinationLat, destinationLng: destinationLng },
          dataType: 'json',
          success: function() { alert('hello!'); },
          error: function() { alert('boo!'); },
          headers: {
              'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
          }  
        });

Route:

Route::post('google/', 'ProfileController@getGoogle');



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2u1BWRq
via IFTTT

Laravel multiple form attributes need to be save in a database

i`m using this view.what i need is fill the database with complete name.

enter image description here This is the view code segment.

 <label>Name with Initials</label>
<div class="input-group">
  <span class="input-group-addon">
    <select id="name_with_initials" name="name">
      <option selected="selected" value="mr">Mr.</option>
      <option value="mrs">Mrs.</option>
      <option value="miss">Miss.</option>
    </select>
  </span>
  <input type="text" name="name_with_initials" class="form-control" placeholder="Name with Initials">
</div>

Here is the controller store function.

$registerdetails = new registerdetails;
          $title = Input::get('name');
          $name  = Input::get('name_with_initials');
        $name_with_initials = $title.' '.$name;
        $registerdetails ->name_with_initials = $request ->name_with_initials;

My model attribute for that is name_with_initials

This works fine,but save only the name not as mr mrswhy is that?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2t4snRQ
via IFTTT

Get in Random Order Laravel

I have made a query about taking 40 question of 7215 in total with this code,

$questions = Question::where([
    'visible' => 'yes',
    'deleted' => 'no'
])
    ->inRandomOrder()
    ->take(40)
    ->get();

but in some cases I get the same question more than 1 time in this query, is there any way to take 1 question only once?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2umL3vI
via IFTTT

Creating 2 different links depending on screen size

This might be a silly question, but I can't seem to find a solution.

I'm creating a site that is also mobile friendly, I'm using bootstrap and laravel.

It has a menu that has a dropdown called "products". If you hover over it, the dropdown will be displayed and the "products" menu will be clickable and takes you to a page with all the product categories.

In order for me to be able to use the hover I removed data-toggle="dropdown" from the dropdown and created a hover function in my js file. The data-toggle="dropdown" allows me to click on "products" without having to go to the product page.

Now the problem I'm having is that when I go to mobile and i press on "products" I go to the product page instead of the dropdown showing.

I was thinking of doing something like this or adding data-toggle="dropdown" via jquery to the link depending on the window size.

@if(window = 700px)
    <a href="{!! url(getSeoLink($grandfather->id)) !!}" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
@else
    <a href="{!! url(getSeoLink($grandfather->id)) !!}" class="dropdown-toggle" role="button" aria-haspopup="true" aria-expanded="false">
@endif

Obviously this doesn't work so I would like to know how I would be able to do something like that. I've looked on the net and I haven't come across anything. Regarding the one for jquery I'm not sure how I would add the data-toggle="dropdown" when the window hits the 700px mark.

My menu

<nav class="navbar navbar-default main_menu_wrapper">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main_menu" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="{!! url('/') !!}" class="navbar-brand">
                <img src="{!! asset("img/logo.jpg") !!}">
            </a>
        </div>

        <div class="collapse navbar-collapse menu_wrapper" id="main_menu">
            <form action="{!! route('search') !!}" method="POST" role="search" class="navbar-form navbar-right search">
                
                <div class="form-group">
                    <input type="text" class="form-control" name="search" placeholder="Search...">
                </div>
                <button type="submit" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span>
                </button>
            </form>

            <ul class="nav navbar-nav navbar-right">
                @foreach($menus_child as $grandfather)
                    @if($grandfather->menu_id)
                        <li>
                    @elseif($grandfather->title == 'Home')
                        <li class="parent {!! menu_active($grandfather->id) !!}">
                    @elseif(count($grandfather->menusP()->where('menu_id', '>', 0)->get()))
                        <li class="dropdown {!! menu_active($grandfather->id) !!}">
                    @else
                        <li class="parent {!! menu_active($grandfather->id) !!}">
                    @endif

                    @if(count($grandfather->menusP()->where('menu_id', '>', 0)->get()))
                        <a href="{!! url(getSeoLink($grandfather->id)) !!}" class="dropdown-toggle" role="button" aria-haspopup="true" aria-expanded="false">
                            {!! $grandfather->title !!} <span class="caret"></span>
                        </a>
                    @else
                        {!! Html::link(getSeoLink($grandfather->id), $grandfather->title) !!}
                    @endif

                    @if(count($grandfather->menusP))
                        <ul class="dropdown-menu">
                            @foreach($grandfather->menusP as $father)
                                @if($father->menu_id)
                                    <li class="parent_child">
                                @else
                                    <li>
                                @endif

                                {!! Html::link(getSeoLink($father->id), $father->title) !!}
                            @endforeach
                        </ul>
                    @endif
                @endforeach
            </ul>
        </div>
    </div>
</nav>

my js that allows a hover

$('ul.navbar-nav li').hover(
    function () {
        $(this).find('> ul').show();
    },
    function () {
        $(this).find('> ul').hide();
    }
);

I hope I made sense. If there is anything else that I might have forgotten to add please let me know.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2t40R6S
via IFTTT

Laravel queued mail not received

I'm trying to use queue for my email sending on Laravel 5.4

Mail::to('email@example.com')->queue(new NotifyCustomer($client));

What works: QUEUE_DRIVER=sqs or database with Mailgun

What works: QUEUE_DRIVER=sync with Mailgun with domain up******.com

What doesn't work: QUEUE_DRIVER=sqs or database with domain up******.com. But, it works for other domains.

Is this an issue with domain up******.com MX entry or DNS setup or something not working at Illuminate\Mail\SendQueuedMailable?

Thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sprH7q
via IFTTT

laravel. echo variable to view from controller

I have some Ajax making a post request to a function in my controller (postIndex) I would like to echo this variable ($a) to the view.

public function postIndex( \Illuminate\Http\Request $request ){
/*
* CODE
*/
$a = "string";
echo $a;

return SOMETHING;
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2t3mzbn
via IFTTT