1

This is on production side (on unbtu Digital Ocean server)

  • "laravel: 5.3"
  • "php": "5.5.9"

Route path : /route/web.php (not in middleware)

Route::get('api/getsymbol-request','MemberTradesController@getSymbolRequest');
Route::get('api/getsymbol','MemberTradesController@getSymbol'); 

Controller:

public function getSymbolRequest(Request $request){
        $symbol = DB::table("symbols")
            ->where("market_id", $request->market_id)
            ->pluck("symbol","id");
        return response() -> json($symbol);
    }

public function getSymbol(){
        $symbol = DB::table("symbols")
            ->pluck("symbol","id");
        return response() -> json($symbol);
    }

http://yourtradelog.com/api/getsymbol-request?market_id=1 //This is not working url I am getting issue WHY THIS IS NOT WORKING

http://yourtradelog.com/api/getsymbol //This is working url

Database tables

    <script>
        $(document).ready(function() {

            $('#exchange').change(function(){
                var exchangeID = $(this).val();
                if(exchangeID){
                    $.ajax({
                        type:"GET",
                        url:"{{url('api/getsymbol-request/')}}?exchange_id="+exchangeID,
                        success:function(res){
                            if(res){
                                $("#market").empty();
                                $("#market").append('<option>Select</option>');
                                $.each(res,function(key,value){
                                    $("#market").append('<option value="'+key+'">'+value+'</option>');
                                });

                            }else{
                                $("#market").empty();
                            }
                        }
                    });
                }else{
                    $("#market").empty();
                }
            });

        });
    </script>
     {!! Form::open(['method'=>'POST', 'action'=> 'MemberTradesController@store']) !!}
 <div class="form-group col-sm-5">
                {!! Form::label('market_id', 'Markets:') !!}
                {!! Form::select('market_id', [''=>'Choose Options'] , null, ['class'=>'form-control', 'id'=>'market'])!!}
            </div>

        <div class="form-group col-sm-10">
            {!! Form::label('symbol_id', 'Symbol:') !!}
            {!! Form::select('symbol_id', [''=>'Choose Options'] ,  null, ['class'=>'symbol_id', 'id'=>'symbol','data-width'=>'60%', 'data-live-search'=>'true'] )!!}
        </div>
 
 <div class="form-group col-lg-4">
                {!! Form::submit('Add trade', ['class'=>'btn btn-success btn-lg']) !!}
            </div>

            {!! Form::close() !!}

10
  • post your routes Commented May 8, 2018 at 10:09
  • route is posted @AdnanMumtaz Commented May 8, 2018 at 10:10
  • your both urls are working fine. maybe you dont have data in your db Commented May 8, 2018 at 10:12
  • see screen shot of DB, there is data in DB @AdnanMumtaz Commented May 8, 2018 at 10:14
  • 1
    put this line in your getSymbolRequest() function: dd($request->all()) and post the output here. Commented May 8, 2018 at 10:16

2 Answers 2

2

I prefer using route parameters like this (see more in the documentation here):

Routes:

Route::get('api/getsymbol-request/{id}','MemberTradesController@getSymbolRequest');
Route::get('api/getsymbol','MemberTradesController@getSymbol'); 

Controller:

public function getSymbolRequest(Request $request, $id){
        $symbol = DB::table("symbols")
            ->where("market_id", $id)
            ->get()
            ->pluck("symbol","id");
        return response() -> json($symbol);
    }

public function getSymbol(){
        $symbol = DB::table("symbols")
            ->pluck("symbol","id");
        return response() -> json($symbol);
    }

Please note that the URL has changed to this format:

http://yourtradelog.com/api/getsymbol-request/1

Sign up to request clarification or add additional context in comments.

7 Comments

this is worked for me... but i dont why my code not worked.... well its good work for me. thank you so much. i dont have enough credit score otherwise i hit it up.
Thanks, you can mark my answer correct as well, if you think it is. I assume you did no get the parameters through the URL, but you can check if you put this line in your getSymbolRequest() function (having the previous route of course): dd($request->all())
@ Bálint Budavölgyi is this ok url for ajax : $.ajax({ type:"GET", url: "{{url('api/getsymbol-request')}}?market_id="+$id,
With the new route format it should be like this: $.ajax({ type:"GET", url: "{{url('api/getsymbol-request/')}}"+$id
yourtradelog.com/api/getsymbol-request{id} if use this url in ajax then, it also not worked.. let me paste here ajax
|
1

Try to this code:

public function getSymbolRequest(Request $request)
{
    $marketID = (int)$request->get('market_id')
    $symbol = DB::table('symbols')
        ->where('market_id', $marketID)
        ->get(['symbol','id']);
    return response()->json($symbol);
}
public function getSymbol()
{
    $symbol = DB::table('symbols')
        ->get(['symbol','id']);
    return response()->json($symbol);
}

1 Comment

$marketID = (int)$request->get('market_id') // Add data type worked for me when I am using MongoDB

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.