Laravel和Android收发

时间:2016-10-02 04:14:28

标签: android laravel laravel-5.3

我是laravel的新手,目前我正在开发一个Android应用程序,我必须调用laravel控制器。 我试图从android调用一个函数(只返回一个字符串,该函数的名称是androidTest),但每次它最终抛出异常
java.io.FileNotFoundException:http://192.168.0.104/LaravelAjaxRes/public/getRequest 我正确检查了URL,完全没问题。我也禁用了CSRF验证,但它仍然没有用! 任何人都可以告诉我缺少什么,是否有任何教程或可以帮助我的东西?提前致谢。 控制器代码:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use DB;

class getRegistrationData extends Controller
{
public function index(Request $request)
{
    if($request->ajax()){
        $data = json_encode($request->all());

        $parse = json_decode($data);



        $teachers_name_array = $this->splitTeacherName($parse->teacher);

        $teacher_id = $this->getTeacherID($teachers_name_array);


        DB::table('lessons')->insert(
            ['title' => $parse->title, 'description' => $parse->description,'teacher_id' => $teacher_id]
        );
    }
    else{

    }

}

public function getTeachersData(Request $request)
{
    if($request->ajax()){
        $teachers = DB::table('teachers')->select('firstname', 'lastname')->get();
        return $teachers;
    }
    else{
        //$teachers = DB::table('teachers')->select('firstname', 'lastname')->get();

    }
}

public function androidTest()
{
    echo 'Some Text';
}





public function splitTeacherName($teacher_full_name)
{
    return explode(" ", $teacher_full_name);
}




public function getTeacherID($teachers_name_array)
{
    $matchNames = ['firstname' => $teachers_name_array[0], 'lastname' => $teachers_name_array[1]];
    $result = DB::table('teachers')->select('id')->where($matchNames)->get();

    foreach ($result as $t_id) 
    {
        $teacher_id = $t_id->id;
    }

    return $teacher_id;
}

public function getLessonData(Request $request)
{
    if($request->ajax()){
        $lessons = 
        DB::select(DB::raw('SELECT d1.* ,d2.* from teachers d1 INNER JOIN lessons d2 where d1.id = d2.teacher_id'));
        return $lessons;
    }
    else{
        return null;
    }
}

}

路线代码:

`Route::get('/', function () {
    return view('welcome');
 });
 Route::post('/register','getRegistrationData@index');

 Route::get('/getRequest','getRegistrationData@androidTest');

 Route::get('/getLessonRequest','getRegistrationData@getLessonData');`

0 个答案:

没有答案