deepu07

deepu07

Member Since 1 Year Ago

Experience Points 17,100
Experience
Level
Lessons Completed 142
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

04 Oct
1 month ago

deepu07 started a new conversation Laravel Query Builder IfElse

Hey folks, Can anyone help me that how to apply if else condition in query builder? for example if my status =1 i want to execute one cond and status !=1 execute other cond. Any help that would be appreciated. Thanks in advance. Here is my query

`//Query Builder

        $this->db->select('id, status, new_class')
        ->from('table1 a')
        ->join('table2 b', 'b.id = a.number')
        ->join('table3 c', 'c.class = a.new_class')
        ->where('c.id', $inputId);

Here if status = 1 i want to stop execution here if status is in [2,3,4] i wanna execute below code too. How can I achieve in laravel query builder.

        ->where_in('status', [ 2, 3, 4 ])
        ->where('b.admin', true)
        ->where('b.teacher', true)
        ->where('b.is_new', false);
    $results = $this->db->get()->result();
01 Oct
1 month ago

deepu07 left a reply on Laravel Query Builder

ya. you're right based on id we won't see any duplicates. I'm removing that cond and I wanna merge rollnum value into one row.

1 bob 24 1234

How to achieve that. any idea..

`$data = \DB::table("table1 AS a") ->select("a.") ->join(\DB::raw("(SELECT id, name, age, COUNT(), FROM table2 GROUP BY b.name, b.age HAVING count(*) > 1 ) as b"), function($join){ $join->on("a.name", "=", "b.name")->on("a.age", "=", "b.age"); }) ->orderBy("a.name") ->get();

deepu07 started a new conversation Laravel Query Builder

Hey folks, I'm stuck-up with query builder. I wanna merge duplicate column values into one row.

for example I have

id name age rollnum 1 bob 24 null 2 bob 24 1234

i wanna see 1 bob 24 1234. How can i do that in below query. Any help that would be appreciated. Thanks in advance.

`//Query Builder

    $data = \DB::table("table1 AS a")
      ->select("a.*")
      ->join(\DB::raw("(SELECT 
          id, name, age, COUNT(*),
          FROM table2
          GROUP BY b.name, b.age
          HAVING count(*) > 1
          ) as b"), function($join){
            $join->on("a.name", "=", "b.name")->on("a.age", "=", "b.age")->on("a.id", ">", "b.id");
      })
      ->orderBy("a.name")
      ->get();

`

28 Sep
1 month ago

deepu07 started a new conversation Laravel Query Builder

Hey folks, I'm stuck-up with query builder. I have one raw sql query it is working when you execute in sequel Pro. but not working in code. can anyone help me on this? Thanks in advance.


SELECT a.*
FROM table1 a
JOIN (SELECT name, age, COUNT(*)
FROM table2 
GROUP BY name, age
HAVING count(*) > 1 ) b
ON a.name = b.name
AND a.age = b.age
ORDER BY a.name

//Query Builder

        $data = \DB::table("table1 AS a")
          ->select("a.*")
          ->join(\DB::raw("(SELECT 
              name, age, COUNT(*),
              FROM table2
              GROUP BY b.name, b.age
              HAVING count(*) > 1
              ) as b"), function($join){
                $join->on("a.name", "=", "b.name")->on("a.age", "=", "b.age");
          })
          ->orderBy("a.name")
          ->get();

        dd($data);      

Error                                                                                                                                                                             
  [PDOException]                                                                                                                                                            
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the rig  
  ht syntax to use near 'FROM table2                                                                                                                
              GROUP BY b.name, b.age'                                                                                                                                                                                                                                                                                          




  
26 Sep
1 month ago

deepu07 left a reply on Laravel Observer BadMethodCallException Method Illuminate\Database\Eloquent\Collection::save Does Not Exist.

Gotcha. so it is trying to create again model instance. that is the reason it is not working. am i right?

deepu07 left a reply on Laravel Observer BadMethodCallException Method Illuminate\Database\Eloquent\Collection::save Does Not Exist.

@Cronix Awesome it worked for me. Thanks. can you tell me why it is not working with $id?

deepu07 left a reply on Laravel Observer BadMethodCallException Method Illuminate\Database\Eloquent\Collection::save Does Not Exist.

Yup if I put rollNumber creation logic in controller it is working. why im using observer is by putting all the logic in controller that looks messy and lots code will stay in controller. for that purpose i'm trying like this. bcse of some reason not working. Anyway thanks @Cronix .

deepu07 left a reply on Laravel Observer BadMethodCallException Method Illuminate\Database\Eloquent\Collection::save Does Not Exist.

I'm getting this back in postman

  #table: "professors"
  #fillable: array:9 [
    0 => "first_name"
    1 => "last_name"
    2 => "roll_number"
    3 => "dob"
  ]
  #connection: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: true
  #attributes: array:11 [
    "first_name" => "test"
    "last_name" => "k"
    "dob" => "1989-07-24"
    "id" => 116
  ]
  #original: []
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [
    0 => "*"
  ]
}```

deepu07 left a reply on Laravel Observer BadMethodCallException Method Illuminate\Database\Eloquent\Collection::save Does Not Exist.

Yes. I'm getting data into my observer if I do DD() it is showing all the information. but the problem is when you write save() or update() simply it is saying BadMethodCallException Method Illuminate\Database\Eloquent\Collection::update does not exist

deepu07 left a reply on Laravel Observer BadMethodCallException Method Illuminate\Database\Eloquent\Collection::save Does Not Exist.

@Cronix I tried but it is not working. At first I tried to update only roll_number and tried to pass all parameters through update method still it is throwing same error. like this BadMethodCallException Method Illuminate\Database\Eloquent\Collection::update does not exist

deepu07 started a new conversation Laravel Observer BadMethodCallException Method Illuminate\Database\Eloquent\Collection::save Does Not Exist.

Hi folks, can anyone help me out on this? I'm getting an error in laravel observer. I have both controller and observer. where controller logic helps me to create a professor record. I wanna use observer to generate a roll_number based on professor record and want to update in same table.

Here is my code

$professor = new Professor;
        $professor->first_name =  Input::get('first_name');
        $professor->middle_name =  Input::get('middle_name');
        $professor->last_name =  Input::get('last_name');
        $professor->dob =  Input::get('dob');
        
            $professor->save();

```OBSERVER
      public function created($id)
    {
        $professor = Professor::findOrFail($id);
        $professor->first_name = Input::get('first_name');
        $professor->last_name = Input::get('last_name');
        $professor->dob =  Input::get('dob');

        $firstNameLetter = strtoupper(substr($professor->first_name, 0, 1));
        $lastNameLetter = substr( $professor->last_name, 0, 1);
        $dateOfBirth = substr($professor->dob, 0,4);

        $rollNumber = $firstNameLetter . $lastNameLetter . '@' . $dateOfBirth;

        $professor = Professor::find($id);
        $professor->roll_number = $rollNumber;
        $professor->update();
    }

HERE Everything im getting a data to my observer but unable to save in DB. getting An error like this for both save() and update()

BadMethodCallException
Method Illuminate\Database\Eloquent\Collection::save does not exist.

Thanks for advance.
20 Sep
1 month ago

deepu07 left a reply on Git

see what files you modified in code git status. I'm files is there you need stash them git stash . after that only you will pull the code from remote. Use some Git UI softwares like sourcetree, tower etc... those are easy to see the changes and also easy to perform the operations.

deepu07 started a new conversation Laravel Model

Hi Folks,

Is Laravel 5.7 V will support model rules or do we need to describe in controller? I used to define rules in Laravel model. jus wondering still it is supporting or not. Thanks in advance

16 Sep
1 month ago

deepu07 started a new conversation Laravel-vue.js

Hi Folks, I got weird error in Vue file.


(found in <Root>)
warn @ app.js:36570
warnNonPresent @ app.js:37876
has @ app.js:37909
(anonymous) @ VM3379:3
Vue._render @ app.js:40521
updateComponent @ app.js:38765
get @ app.js:39119
Watcher @ app.js:39108
mountComponent @ app.js:38772
Vue.$mount @ app.js:44517
Vue.$mount @ app.js:46916
(anonymous) @ app.js:13931
__webpack_require__ @ app.js:20
Object.defineProperty.value @ app.js:13881
__webpack_require__ @ app.js:20
(anonymous) @ app.js:63
(anonymous) @ app.js:66
app.js:36570 [Vue warn]: Property or method "name" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

(found in <Root>)
warn @ app.js:36570
warnNonPresent @ app.js:37876
has @ app.js:37909
(anonymous) @ VM3379:3
Vue._render @ app.js:40521
updateComponent @ app.js:38765
get @ app.js:39119
Watcher @ app.js:39108
mountComponent @ app.js:38772
Vue.$mount @ app.js:44517
Vue.$mount @ app.js:46916
(anonymous) @ app.js:13931
__webpack_require__ @ app.js:20
Object.defineProperty.value @ app.js:13881
__webpack_require__ @ app.js:20
(anonymous) @ app.js:63
(anonymous) @ app.js:66
app.js:36570 [Vue warn]: Property or method "description" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

(found in <Root>)```

Here is My app.js code
`new Vue({
    el: '#app',

    data: {
       name: ' ',
       description: ' '
    },

        methods: {
        },
});`

#blade file I'm loading app.js file 
` <script src="/js/app.js"></script>`

Any help. Thanks in advance
15 Sep
1 month ago

deepu07 started a new conversation Laravel-homestead

Hey Folks, Im new to homestead. I'm struggling with creating two laravel projects in homestead. Can anyone help me on this? here is my config code:

#YAML file (I have two laravel projects in Sites foldes.)


    - map: ~/Development/sites/Laravue
      to: /home/vagrant/sites/Laravue

    - map: ~/Development/sites/Lara-vue
      to: /home/vagrant/sites/Lara-vue

sites:

    - map: Laravue.test
      to: /home/vagrant/sites/Laravue/public

    - map: Lara-vue.test
      to: /home/vagrant/sites/Lara-vue/public```

#here is my hosts file

127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost

192.168.10.10 Laravue.test 192.168.10.10 Lara-vue.test


I'm getting one project for two URLs (Laravue.test and Lara-vue.test both are routing to same project)

Anyone have any idea why it is loading one project. Thanks in advance

14 Sep
1 month ago

deepu07 left a reply on Laravel-vue

So do i need t setup in .env file ? or somewhere? I'm using Mac with MAMP

deepu07 left a reply on Laravel-vue

yup that resolved my problem it is throwing 404 error . This is my form <form method="POST" action="/projects" @submit.prevent="onSubmit">

and #web.php

Route::post('projects', '[email protected]')->name('projects');```

looks like it not recognizing the route. How can I resolve that? can you help me on this..

deepu07 started a new conversation Laravel-vue

Hello Folks, I'm trying to build a blog with Laravel-vue. But I'm unable to load vue.js. It is getting an error. I couldn't find why it is not loading can anyone help me?

Thanks in advance

    <div id="app" class="container">
        @include ('projects.list')      

        <form method="POST" action="/projects" @submit.prevent="onSubmit">
        @csrf
            <div class="control">
                <label for="name" class="label">Project Name:</label>
                <input type="text" id="name" name="name" class="input"> 
            </div>

            <div class="control">
                <label for="description" class="label">Project Description:</label>
                <input type="text" id="description" name="description" class="input">
            </div>
    <br>
            <div class="control">
                <button class="button is-primary">Create</button>
            </div>
        </form>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <script src="../resources/assets/js/app.js"></script>
</body>
</html>```


```const app = new Vue({
    el: '#app',

    data: {

    },

    methods: {
        onSubmit() {
           axios.post('/projects', this.$data);
        }
    },
});

#ERROR

In console im getting GET http://localhost:8888/larapower/public/resources/assets/js/app.js 404 (Not Found)

13 Sep
2 months ago

deepu07 left a reply on Laravel-Vue Route URL

It would be a POST request. somehow i'm missing after hitting a submit button it it redirecting to the http://localhost/projects. That causes not found exception.

deepu07 left a reply on Laravel-Vue Route URL

@AdhamLap it is not a POST request?

deepu07 started a new conversation Laravel-Vue Route URL

Hey Folks, Hope you are doing well. I have a small question. I'm building a site with Laravel-Vue.js I'm unable to hit correct URL. I didn't whats wrong with that. Tried but no clue can anyone help me on this.

html code (create.blade.php)

        @include ('projects.list')
        <form method="POST" action="/projects" @submit="onSubmit">```
app.js
```new Vue({
    el: '#app',

    data: {
        name: ' ',
        description: ' ',
    },

        methods: {
            onSubmit() {
               axios.post('/projects', this.$data);
            }
        },
});```

Laravel code 
```Route::get('projects/create', '[email protected]');
Route::post('projects', '[email protected]');```

Create http://localhost:8888/blog/public/projects/create is working after clicking on submit button it is routing to `http://localhost:8888/projects` . 

Can anyone help me on this. Thanks in Advance.


25 Aug
2 months ago

deepu07 started a new conversation Sql Query

Hi Folks,

I'm super confused that calling JOIN after making many LEFT JOIN's in SQL query is technical wrong ? I googled but I haven't find any info. Can anyone helped me on this. Looking forward. Thanks in advance.

08 Jun
5 months ago

deepu07 left a reply on How To Pass DB Array Values To Blade View

#original: array:9 [▼ "id" => 6 "client_id" => 1 "user_id" => null "location" => "Hyderabad, Telangana, India" "airport" => "["HYD - Hyderabad Airport","BPM - Begumpet"]" "start_date" => "06/13/2018 12:00 AM" "end_date" => "06/14/2018 12:01 AM" "created_at" => "2018-06-08 04:28:35" "updated_at" => "2018-06-08 04:28:35"

deepu07 left a reply on How To Pass DB Array Values To Blade View

  #items: array:6 [▼
    0 => Meeting {#529 ▼
      +timestamps: true
      #table: "meetings"
      #casts: array:1 [▶]
      #fillable: array:6 [▶]
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:9 [▶]
      #original: array:9 [▼
        "id" => 1
        "client_id" => 4
        "user_id" => null
        "location" => "Hyderabad, Telangana, India"
        "airport" => "HYD - Hyderabad Airport"
        "start_date" => "06/11/2018 12:06 PM"
        "end_date" => "06/12/2018 12:00 AM"
        "created_at" => "2018-06-07 00:09:28"
        "updated_at" => "2018-06-07 02:19:15"
      ]
      #changes: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:2 [▼
        "client" => Client {#574 ▼
          +timestamps: true
          #table: "clients"
          #fillable: array:3 [▶]
          #connection: "mysql"
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:6 [▶]
          #original: array:6 [▶]
          #changes: []
          #casts: []
          #dates: []
          #dateFormat: null
          #appends: []
          #dispatchesEvents: []
          #observables: []
          #relations: []
          #touches: []
          #hidden: []
          #visible: []
          #guarded: array:1 [▶]
        }
        "user" => null
      ]
      #touches: []
      #hidden: []
      #visible: []
      #guarded: array:1 [▼
        0 => "*"
      ]
    }
    1 => Meeting {#530 ▶}
    2 => Meeting {#531 ▶}
    3 => Meeting {#532 ▶}
    4 => Meeting {#533 ▶}
    5 => Meeting {#534 ▶}
  ]
}```

deepu07 started a new conversation Display An Json_decode Values In Blade File

Hi everyone,

How to display json_decode values into blade view. here is my code to display single author and multiauthor books. Any help that would be appreciated Thanks in advance

      <tr>
        @if (json_encode($book['author']) !== 1 )
        <td>{{{ json_decode(json_encode($book['author'][0]),true) }}} &
        {{{ json_decode(json_encode($book['author'][1]),true) }}}</td>
        @else  
        <td>{{{ $book['author'][0] }}}</td>
        @endif 
     </tr>```

deepu07 left a reply on How To Pass DB Array Values To Blade View

I tried like this

        <td>{{{ json_decode(json_encode($meeting['airport'][0]),true) }}} &
        {{{ json_decode(json_encode($meeting['airport'][1]),true) }}}</td>
        @else  
        <td>{{{ $meeting['airport'][0] }}}</td>
        @endif```
but getting only getting where we have 2 values in array

deepu07 left a reply on How To Pass DB Array Values To Blade View

@arukomp Getting an error implode(): Invalid arguments passed

deepu07 left a reply on How To Pass DB Array Values To Blade View

@arukomp only 5th record is having airports array(2 values) remaining all records they have only one. How can I manage this? any help

deepu07 left a reply on How To Pass DB Array Values To Blade View

@arukomp We are getting collection of meetings. there are total 5 records in DB. But 5th record they have array data value in airport.

      <tr>
        <td>{{$meeting['id']}}</td>
        <td>{{ $meeting->client['company_name'] }}</td>
        <td>{{ $meeting->client['contact_person'] }}</td>
        <td>{{$meeting['location']}}</td>
        @if (isset($meeting['airport']))
        <td>{{{ json_encode($meeting['airport']) }}}</td>
        @else
        <td>{{$meeting[0]['airport']}}</td>
        @endif
        @php dd($meetings) @endphp```

deepu07 left a reply on How To Pass DB Array Values To Blade View

@Inquisitive It is not working I was tried before. After some research Idid like this

        <td>{{{ json_encode($meeting['airport']) }}}</td>
        @else
        <td>{{$meeting[0]['airport']}}</td>
        @endif```

Output: ["HYD - Hyderabad Airport","BPM - Begumpet"]

But I want to convert user readable format output 

deepu07 started a new conversation How To Pass DB Array Values To Blade View

Hi folks, I have array values in database. Can anyone help me on this how to display in view? Thanks In advance

      @foreach($meetings as $meeting)
      <tr>
        <td>{{$meeting['id']}}</td>
        <td>{{ $meeting->client['company_name'] }}</td>
        <td>{{ $meeting->client['contact_person'] }}</td>
        <td>{{$meeting['location']}}</td>
        <td>{{$meeting['airport'] }}</td>```

DB values looks like this
``` ["HYD - Hyderabad Airport","BPM - Begumpet"]```

Tried with @foreach but no luck
07 Jun
5 months ago

deepu07 started a new conversation Selecting Multiple Values From Dynamic Dropdown (HTML-jQuery) And Send To Controller

Hi Folks, Here I'm trying to get multiple values into my controller from Front-end dynamic Drop-down selection by using HTML-jQuery. I'm able select multiple options by pressing SHFT key but when I DD(); in controller I'm getting only one value. How can I achieve multiple dynamic selected values into Back-end. any help that would be appreciated. Thanks in Advance.

//HTML

                  <label for="airport">Nearest Airport:</label>
                  <select id="AirportCode" name="AirportCode" multiple="multiple" class="form-control" placeholder="Select an Airport">
                    <option value="" disabled selected>Select Nearest Airport</option>
                    <option value="AirportCode" selected="selected"><div id="table"></div></option>
                  </select>
                </div>```

//jQUery

``` $.ajax({
                type: 'GET',
                url: url ,
                dataType: 'json',
                headers: {
                  accept: "application/json",
                  authorization:"key "+ bearer_token
                }
              }).done(function(data) {

              var options = '<option value="" disabled="" selected="">Select Nearest Airport</option>';
              data= data|| {};

               $("select option:selected" ).each( data, function( key, value ) {
                   options += '<option value="'+value.code+ ' - ' +value.name+'">'+value.code+ ' - ' +value.name+'</option>';
               })
            
                $('#AirportCode').html(options);
            })```

//Controller

``` public function store(Request $request)
    {
        $meeting = new Meeting;
        $meeting->airport = $_POST['AirportCode'];
        $meeting->save();

        return redirect('/meetings');
    }```
06 Jun
5 months ago

deepu07 left a reply on Controller Edit Method (Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message)

@Inquisitive Thanks man. I did big mistake that I commented my update method in y controller.

              {{csrf_field()}}
              <input name="_method" type="hidden" value="PATCH">``` 

deepu07 started a new conversation Controller Edit Method (Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message)

Hi Folks, Im Trying to update meeting details. But getting an error I didn't get why it is happening. Any help that would be appericated.

Thanks in Advance

//Blade file

 <form method="PATCH" action="{{action('[email protected]')}}">
            {{csrf_field()}}
            <input name="_method" type="hidden" value="PATCH">```

//controller
``` public function edit($id)
    {
        $input = Input::all();

        $meeting = Meeting::find($id);
        $meeting->update($input);
        $result = $meeting->save();

        return view('meetings.edit', compact('id', 'meeting'));
      
    }```

//error
Error: ```Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message```
05 Jun
5 months ago

deepu07 started a new conversation Displaying Data From Dynamic Dropdown Selection By Using Laravel-jQuery Ajax Calling

Hi Folks, I'm trying to display data from dynamic dropdown selection. I'm new to Laravel-jQuery Ajax Calling. I want to display books list by selecting author names from dropdown. How can I achieve that. any suggestions that would be appreciated. Looking forward Thanks in Advance.

//Blade.php

   
        <link rel="stylesheet" href="{{ asset('css/home.css') }}" type="text/css"/>
        <link rel="stylesheet" href="{{asset('css/app.css')}}">

    </head>

    <body>

        <div class="container">
              <div class="row col-md-12">
                <div class="form-group col-md-12">
                  <label for="authorName">Select Author Name:</label>
                  <select name="authorName" id="authorName" class="form-control">
                    <option value="" disabled selected>Select Author Name</option>
                     @foreach($authors $author)
                      <option value="{{$author->id}}">{{ $author->id }} {{ $author->name }} </option>
                     @endforeach
                  </select>
                </div>
              </div>

          <table class="table table-striped" id="table">
            <thead>
              <tr>
                <th>Book ID</th>
                <th>Location</th>
                <th>Price</th>
                <th>Start Date</th>
                <th>End Date</th>
              </tr>
            </thead>
            <tbody id="tbody">
              @foreach($authorBooks  as $authorBook)
              <tr>
                <td>{{$authorBook['id']}}</td>
                <td>{{$authorBook['location']}}</td>
                <td>{{$authorBook['price']}}</td>
                <td>{{$authorBook['start_date']}}</td>
                <td>{{$authorBook['end_date']}}</td> 
              </tr>
              @endforeach
            </tbody>
          </table>
        </div>

            <!-- Ajax Scripts -->
        <script type="text/javascript">
        $(document).ready(function() {
            $('select[name="authorName"]').on('change', function() {
                var authorID = $(this).val();
                console.log(authorID );
                if(authorID ) {
                    $.ajax({
                        url: '/authorsList/ajax/'+authorID ,
                        type: "GET",
                        dataType: "json",

                         $('#table').find('tbody').append([
                            '<tr>',
                                '<td>{{$authorBook['id']}}</td>',
                                '<td>{{$authorBook['location']}}</td>',
                                '<td>{{$authorBook['price']}}</td>',
                                '<td>{{$authorBook['start_date']}}</td>',
                                '<td>{{$authorBook['end_date']}}</td>',
                            '</tr>'
                            ].join(''));
                    });
                  }
            </script>```

//Controllers Code

public function authorsList() { $authors= Author::all();

    return view('AuthorBooksList')->with(array('authors' => $authors));
}

public function authorBooksList($authorId)
{
    $input = func_get_args($authorId);
    $authorId= implode(' ', $input);

    $authorBooks  =  \DB::table('books')
                        ->leftJoin('authors', 'authors.id', '=', 'books.author_id')
                        ->where(author_id', '=', $authorId)
                        ->select('location', 'price', 'start_date', 'end_date')
                        ->get();

    return json_encode($authorBooks  );
}

//Route.php
Route::get('authorsList',array('as'=>'authorsList','uses'=>'[email protected]'));
Route::get('authorsList/ajax/{id}',array('as'=>'authorsList.ajax','uses'=>'[email protected]'));

deepu07 started a new conversation How To Get Bootstrap Datetime In Controller

Hi Folks,

I have one form in that I'm using datetime picker in that. but I'm unable to get selected date in controller how can achieve that. any help that would be appreciated.

                  <label for="name">Start Date:</label>
                    <div class='input-group date' id='StartDate'>
                        <input type='text' class="form-control" id="SDate" />
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>```

``` <script type="text/javascript">
            $(document).ready(function() {
                $(function () {
                    $('#StartDate').datetimepicker({
                    });
                    $('#EndDate').datetimepicker({
                        useCurrent: false 
                    });
                    $("#StartDate").on("dp.change", function (e) {
                        $('#EndDate').data("DateTimePicker").minDate(e.date);
                    });
                    $("#EndDate").on("dp.change", function (e) {
                        $('#StartDate').data("DateTimePicker").maxDate(e.date);
                    });
                });
            });
        </script>```

I tried in multiple ways i.e. `dd(Input::get('SDate'));`
`dd(date("Y-m-d", strtotime(Input::get("StartDate"))));`
dd($_POST['SDate']);` but no luck at all.

Thanks in Advance.
04 Jun
5 months ago

deepu07 left a reply on Google Map API Integration In Laravel 5.6

@freeccboy I got that I'm using google map API

03 Jun
5 months ago

deepu07 left a reply on How To Enable Bootstrap-jquery Datetimepicker

It didn't solved @Cronix see my post title I wanna enable the datetimepicker.

deepu07 left a reply on How To Enable Bootstrap-jquery Datetimepicker

@Cronix for that. I'm using this datetimepicker laravel So that's what I' confusing. Anyway thanks man.

deepu07 left a reply on How To Enable Bootstrap-jquery Datetimepicker

@Cronix But I'm using in composer not npm. There is no installion process for composer ;)

deepu07 left a reply on How To Enable Bootstrap-jquery Datetimepicker

@Cronix I would like to use datetimepicker

deepu07 started a new conversation How To Enable Bootstrap-jquery Datetimepicker

Here I'm trying to use bootstrap-jquery datetimepicker for my form. but unfortunately I'm getting an error that datetimepicker undefined function. here is my code `

 <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker.min.css" rel="stylesheet"/>
 <script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script>

 <script type="text/javascript">
 $('#date').datetimepicker({
   todayHighlight: true,
   format: 'dd/mm/yyyy',
   startDate: new Date()   
  });
 </script>```

Uncaught TypeError: $(...).datetimepicker is not a function

Any help that would be appreciated. Thanks in advance 

deepu07 left a reply on Laravel Store Method

By using a value with an {{$author->id}} in option tag. problem got resolved. thanks

02 Jun
5 months ago

deepu07 started a new conversation Laravel Store Method

Hi Folks,

I have one question for you guys. any help that would be appreciated.

Here is my question ```I have one form (books) that has a drop-down with author names and book title and book price columns. but in my books table I have author_id is a foreign keyI want to save selected author name in the format ofid` in books table. How can I achieve that.

Thanks In advance.

30 May
5 months ago

deepu07 left a reply on Google Autocomplete Address

Hi @tisuchi Can you help on this? how you achieved this address auto-populate task by using Google map API? Looking forward..

Thanks

29 May
5 months ago

deepu07 started a new conversation Google Map API Integration In Laravel 5.6

Can anyone suggest suitable packages to consume google map api and want to auto-populate the locations.

Thanks In Advance.

28 May
5 months ago

deepu07 started a new conversation Display A Records With Laravel Relationships In View

Hi Folks,

here is my problem. can you help me out.

  1. book belongsTo one author. (author_id is a foreign key in book table)
  2. Author hasMany books. (book_id is a foreign key in author table)

How to access author in books view.

I tried like this

     <tr>
       <td>{{$book['id']}}</td>
       <td>
         @foreach ($book->author as $author)
               {{ $author->name }}
        @endforeach
     </tr>
@endforeach ```

I'm unable to get author details in my view.  I'm getting an error. Please help me out on this. 
Thanks in advance

17 May
5 months ago

deepu07 started a new conversation Regarding Group

Hello Folks, Hope you guys are doing good. DO you guys have any WhatsApp group for PHP or Laravel? If you know anyone please let me know.

Thanks in advance