lundi 27 février 2017

Internal server error in laravel 5.3

I am trying to validate a form data if it exist in database. I'm using jquery validate plugin.But I am getting the internal server error 500. Here is my validation.js file

$(document).ready(function () {
    $("#test-form").validate({
        rules: {
            projectname:{
                required:true,
                minlength:5,
                remote:{
                    url: '/checkProject',
                    type: "post"
                }
            }
        },
        messages:{
            projectname:{
                required: "Please enter at least 5 character project name!",
                remote:"This project already exist. Please enter a diffrent name!"
            }
        }
    });

});

here is my web.php

Route::post('/checkProject','ProjectController@checkProject');

and controller

public function checkProject(Request $request){
        $RequestedProject = "Project Y";
        $RegisteredProject = Project::all();
        $flag = "true";
        foreach ($RegisteredProject as $item){
           if( $item['name'] == $RequestedProject){
               $flag = "false";
               break;
           }
        }
        echo $flag;
    }

what is the problem



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

Run a raw SQL statement to rename an index in a Laravel migration

I want to run the following raw SQL statement in a Laravel migration:

RENAME INDEX offer_venue_id_fk_idx TO offers_venue_id_index

How can I do this?



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

Rename an index in Laravel 5

I want to rename an index in Laravel 5.

In a previous migration a column was created for table named a like so:

$table->unsignedInteger('foo')->index('blah');

I want to rename the index so that it uses the default Laravel notation.

i.e. I want to rename the blah index to a_blah.

I know how to rename a normal column, like so:

$table->renameColumn('from', 'to');

But the documentation does not mention how to rename indexes.

How can I do this?



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

Which is the best choice between Querry builder && Eager loading in laravel 5.4?

I have 3 table: users, posts and comments. I have 2 way for selecting data.

$posts = User::select('id')
            ->with(['post' => function( $query ){
                $query->with(['comments']);
            }])->find($userId);

and

$posts = DB::table('posts')
        ->leftjoin('comments', 'posts.id', '=', 'comments.post_id')
        ->where('user_id', $userId)
        ->get();

I see method 2 is faster than method 1 in some records. I don't know what happen when I have 1000 or 10000 records. Can you tell me which is better? Thanks for any help.



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

Uncaught Referrence error

I am using laravel 5.3. I am trying to validate form data with jquery validate plugin. After data validation i want to fire an ajax call. Here is my code

<!doctype html>
<html>
<head>
    <meta name="_token" content="{!! csrf_token() !!}"/>
    <script src="http://ift.tt/1dLCJcb"></script>
    <script src="http://ift.tt/1NKbGQl"></script>
    <link href="http://ift.tt/1jAc5cP" rel="stylesheet" type="text/css" />
    <script src="http://ift.tt/1jAc4pg"></script>
    <script src="/js/bootstrap-tagging.js"></script>
    <link type="text/css" href="/css/bootstrap-tagging.css" rel="stylesheet">
    <script src="/js/tapered.bundle.js"></script>
    <script src="http://ift.tt/2iFPHiv"></script>
    <script src="/js/validation.js"></script>
    <script>
        $(document).ready(function() {
            function ajaxCall() {
                console.log("event occured");
                $.ajax({
                    type: "POST",
                    url: '/storeproject',
                    data: { _token: "" },
                    success: function( msg ) {
                        console.log(msg);
                    }
                });
            }
        });
    </script>
</head>
<body>
<form role="form" method="POST" action="javascript:ajaxCall()" id="test-form">
    {!! csrf_field() !!}
    <label>Project Name</label>
    <input class="form-control" id="projectName" placeholder="Name" name="projectname" type="text" autofocus="">
    <input type="submit"  id="submit" name="submit" class="btn btn-primary" value="Add">
</form>
</body>
</html>

When i hit the add button gives me the error

VM681:1 Uncaught ReferenceError: ajaxCall is not defined at :1:1

but if I avoid the document ready function it works fine. What is the problem?



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

dimanche 26 février 2017

Laravel: Layouts.master not found

I built the demosite in Laravel, but I got the following error:

ErrorException in FileViewFinder.php line 137: View [layouts.master] not found.(View: /var/www/html/project/laravel/laravel/resources/views/page.blade.php)

The master.blade.php is next to the page.blade.php, both are in resources/views

master.blade.php

<html>
    <head>
        <title>@yield('title')</title>
    </head>
    <body>
        @section('sidebar')
        This is the master sidebar.
        @show
        <div class="container">
        @section('content')
        </div>
    </body>
</html>

page.blade.php

@extends('layouts.master')
@yield('title', 'Page Title')
@section('sidebar')
@parent
<p>This is appended to the master sidebar.</p>
@endsection
@section('content')
<h2></h2>
<p>This is my body content.</p>
@endsection

What goes wrong? I working from this tutorial.



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

How to recording the user's device in laravel

how to add data device (tablet, mobile, desktop) if users access to one of the devices when logged on, then the data was recorded.

i use packages jenssegers/agent

table device having column: device_name, date

i try, but can't record in table

this my code in LoginController.php

   public function check(){
      $agent = new Agent();
      $dt = Carbon::now();

      if ( $agent->isDesktop() == true )
      {
        DB::table('device')->insert([
           ['device_name' => 'desktop', 'tgl' => $dt->toDateString()],
       ]);
      }

      elseif ($agent->isTablet() == true) {
        DB::table('device')->insert([
           ['device_name' =>'tablet', 'tgl' => $dt->toDateString()],
       ]);
      }

      elseif ($agent->isMobile() == true) {
        DB::table('device')->insert([
           ['device_name' => 'mobile', 'tgl' => $dt->toDateString()],
       ]);
     }

    }

please help me, thank you very much...



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