mardi 30 mai 2017

Timestamps in laravel is not working well

What happen to my created_at and updated_at fields? Im using laravel5.1. I have this on my table:

=====================================
Name               type               default
created_at   |   timestamp  |  0000-00-00 00:00:00
updated_at  |   timestamp  |  0000-00-00 00:00:00



Migration is this:

$table->increments('id')->unsigned();
$table->timestamps();


Result
The red is my actual date, the first green is the created_at and the second green is the updated_at enter image description here



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

lundi 29 mai 2017

How to get the created_at in pivot table in laravel

Im confused how to get the created_at column in my pivot table. I have exam_user table with created_at and updated_at column. Now, I have this code in my view:

@if($exam->users()->where('user_id', Auth::user()->id)->exists())
    
    <div class="alert alert-success">You have done with this exam.</div>
@else

Any idea for this?



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

Laravel correct way to bind data in raw sql string

I am using ? identifier for my DB::insert() and its working great, but I am having problem for my DB::select(), the ? doesn't work.

Here's my query:

    $result = DB::select("
        SELECT `department_code`, `name` FROM `tbl_departments` 
        WHERE `department_code` LIKE '%?%' OR `name` LIKE '%?%'
    ", [
        $searchkey, $searchkey
    ]);



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

Save user data on click button

I'm working on laravel 5.4 and I have this code:

  public function apply($id){
        $user = User::where('id', $id)->get()->first();
        $data = [
          'name' => $user->first_name,
          'family' => $user->last_name,
          'email' => $user->email,
          'username' => $user->username,
          'gender' => $user->gender,
          'birthday' => $user->birthday,
          'cv' => $user->cv,
          'about' => $user->about,
          'education' => $user->education,
          'experiences' => $user->experiences,
        ];

        Mail::send('emails.apply', $data, function ($message) use ($company)
        {

            $message->from('noreply@gmail.com', 'Robert Nicjoo');
            $message->subject('New Apply');
            $message->to($company->email, 'Admin')

        });

        Session::flash('success', 'Your application was sent to company.');
        return redirect()->back()->with('session', $data);
  }

This will send email to company when user click on apply button and send user info to them, now I also want to save data of the user include user_id, ad_id and company_id in another table so both user and company owners can have access to their history of applied ads.

I also have this table to save data on:

  public function up()
    {
        Schema::create('applies', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->integer('ad_id')->unsigned();
            $table->integer('company_id')->unsigned();
            $table->timestamps();
        });

        Schema::table('ads', function($table) {
            $table->foreign('user_id')->references('id')->on('users');
            $table->foreign('ad_id')->references('id')->on('ads');
            $table->foreign('company_id')->references('company_id')->on('ads');
        });
    }

but in my controller (first codes) I need to know how to save those information in new table (second codes)?



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

database conection with laravel

Hi I'm developing an application with laravel 5.2, I'm triying to connect a remote database, if I do that in the command line I have to write this:

mysql -u root -p -h 'remote_ip' --skip-secure-auth

if I write that in the command line I don't have any problem. But I have to do the connection with laravel, how can I put the option

--skip-secure-auth on my database.php file

'estudiantesdb' => [
        'driver' => 'mysql',
        'host' => 'remote_ip',
        'port' => '3306',
        'database' => 'estudiantesdb',
        'username' => 'root',
        'password' => 'root_password',
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
    ],



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

Laravel 5 Eloquent Relationship with Pivot Table

I have three tables:

  • Users (id, name, email)
  • Competitions (id, name, user_id)
  • Competitors (id, user_id, competition_id)

I wish to set up an eloquent relationship between the three tables. The competitors table is a pivot table for the other two tables. So far I have the following code, which allows me to list all competitions a user owns and allows me to add a competitor to a competition. However, I am struggling to get user details of all competitors in competition

class User {
  public function competitions() {
    return $this->hasMany(Competition::class);
  }
}

class Competition {
  public function join($user_id = 0) {
    $user_id = ($user_id == 0) ? \Auth::id() : (int)$user_id;

    $competitor = new Competitor(['user_id' => $user_id]);

    $this->competitors()->save($competitor);
  }

  public function users() {
    return $this->belongsTo(User::class);
  }

  public function competitors()
  {
    return $this->hasMany(Competitor::class);
  }
}

class Competitor {

}

What do I need to add to the relationships to return all competitors in a competition. Ideally I want to be able to do something likes this:

foreach($competition->competitors as $competitor) {
  echo $competitor->name.' '.$competitor->email; // etc
}



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

Web app doesn't start - Displaying optimal route with Google JS API

first of all i am a beginner in programming. My question is why doesn't my web application start on submit.

I am using Google JavaScript API for calculating optimal route and i have been developing this web app in NetBeans with Laravel 5.

The goal of this application is to get locations from DB and display that locations on Google map and also to display the optimal driving route.

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Waypoints in directions</title>
    <style>
      #right-panel {
        font-family: 'Roboto','sans-serif';
        line-height: 30px;
        padding-left: 10px;
      }

      #right-panel select, #right-panel input {
        font-size: 15px;
      }

      #right-panel select {
        width: 100%;
      }

      #right-panel i {
        font-size: 12px;
      }
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
        float: left;
        width: 70%;
        height: 100%;
      }
      #right-panel {
        margin: 20px;
        border-width: 2px;
        width: 20%;
        height: 400px;
        float: left;
        text-align: left;
        padding-top: 0;
      }
      #directions-panel {
        margin-top: 10px;
        background-color: #FFEE77;
        padding: 10px;
        overflow: scroll;
        height: 174px;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
   <div id="right-panel">
    <div>


    <br>
      <input type="submit" id="submit">
    </div>
    <div id="directions-panel"></div>
    </div>

   <?php

//$lokacije = locations, nar = is a table in db, Adresa = is a row (adress)
$lokacije = DB::table('nar')->pluck('Adresa');
echo json_encode($lokacije);

?>

    <script>

    var start = "Dolac 8, Rijeka";
    var end =  "Dolac 15, Rijeka";
    var lokacije = <?php echo json_encode($lokacije) ?>;
      function initMap() {
        var directionsService = new google.maps.DirectionsService;
        var directionsDisplay = new google.maps.DirectionsRenderer;
        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 12,
          center: {lat: 45.328568, lng: 14.440477}  
        });
        directionsDisplay.setMap(map);

        document.getElementById('submit').onsubmit( function() {
          calculateAndDisplayRoute(directionsService, directionsDisplay);
        });
      }

      function calculateAndDisplayRoute(directionsService, directionsDisplay) {
  var waypts = [];
  var checkboxArray = lokacije;
  for (var i = 0; i < checkboxArray.length; i++) {
    if (checkboxArray.options[i].selected) {
      waypts.push({
        location: checkboxArray[i].value,
        stopover: true
      });
    }
  }
        directionsService.route({
          origin: start,
          destination: end,
          waypoints: waypts,
          optimizeWaypoints: true,
          travelMode: 'DRIVING'
        }, function(response, status) {
          if (status === 'OK') {
            directionsDisplay.setDirections(response);
            var route = response.routes[0];
            var summaryPanel = document.getElementById('directions-panel');
            summaryPanel.innerHTML = '';
            // For each route, display summary information.
            for (var i = 0; i < route.legs.length; i++) {
              var routeSegment = i + 1;
              summaryPanel.innerHTML += '<b>Route Segment: ' + routeSegment +
                  '</b><br>';
              summaryPanel.innerHTML += route.legs[i].start_address + ' to ';
              summaryPanel.innerHTML += route.legs[i].end_address + '<br>';
              summaryPanel.innerHTML += route.legs[i].distance.text + '<br><br>';
            }
          } else {
            window.alert('Directions request failed due to ' + status);
          }
        });
      }
    </script>
    <script async defer
    src="http://ift.tt/2r5BfaE">
    </script>
  </body>
</html>



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