protect my routes - print my Json

1

I am trying to avoid printing my Json format directly (or I do not know if there is any other way)

What happens is that when I access my route in this way

http://blissre.test/projects/

I upload my projects

So far so good, when loading the projects page. axios does the rest extracts my information that I have in my BD and I'm printing with vue.Js

getLista:function(){

	var url = '/projects/';

	axios.get(url).then(response=>{
		
		this.listaPro=response.data

	}).catch(error =>{
		
		console.log(error.data);
		miEstilo();
		
		toastr.error('Error al obtener proyectos');
	});
},

Excellent everything fine

my controller has it this way

 public function index()
    {
        //

       return view('proyectos.index');


    }

which shows me that route.

but when I access my route in this way, I upload all my Json on the page, will there be any way to avoid showing that information?

http://blissre.test/projects/index

[
{
"id": 4,
"titulo": "soy 2",
"antecedentes": "2",
"problematica": "2",
"justificacion": "2",
"objetivoG": "2",
"objetivoE": "2",
"tags": "2",
"status": 0,
"user_id": 1,
"profe_id": null,
"created_at": "2018-03-30 15:29:10",
"updated_at": "2018-03-30 15:29:10"
},
{
"id": 8,
"titulo": "soy 8",
"antecedentes": "gfg",
"problematica": "gfd",
"justificacion": "gdfgfg",
"objetivoG": "dfg",
"objetivoE": "dfgdff",
"tags": "gdfg",
"status": 0,
"user_id": 1,
"profe_id": null,
"created_at": "2018-03-30 16:13:26",
"updated_at": "2018-03-30 16:13:26"
},
{
"id": 9,
"titulo": "sou 9",
"antecedentes": "999",
"problematica": "jkjdsds",
"justificacion": "9999",
"objetivoG": "999999999",
"objetivoE": "99999",
"tags": "99999",
"status": 0,
"user_id": 1,
"profe_id": null,
"created_at": "2018-03-30 16:14:02",
"updated_at": "2018-03-30 16:14:02"
},
{
"id": 10,
"titulo": "soy 10",
"antecedentes": "lkjl",
"problematica": "10",
"justificacion": "101",
"objetivoG": "10",
"objetivoE": "10",
"tags": "100",
"status": 0,
"user_id": 1,
"profe_id": null,
"created_at": "2018-03-30 16:14:29",
"updated_at": "2018-03-30 16:14:29"
},
{
"id": 11,
"titulo": "11",
"antecedentes": "1111",
"problematica": "111",
"justificacion": "111",
"objetivoG": "111",
"objetivoE": "111",
"tags": "1111",
"status": 0,
"user_id": 1,
"profe_id": null,
"created_at": "2018-03-30 16:32:00",
"updated_at": "2018-03-30 16:32:00"
},
{
"id": 12,
"titulo": "12",
"antecedentes": "12",
"problematica": "12",
"justificacion": "12",
"objetivoG": "12",
"objetivoE": "12",
"tags": "12",
"status": 0,
"user_id": 1,
"profe_id": null,
"created_at": "2018-03-30 16:32:28",
"updated_at": "2018-03-30 16:32:28"
},
{
"id": 13,
"titulo": "15",
"antecedentes": "fghfg",
"problematica": "ghfgh",
"justificacion": "hfghf",
"objetivoG": "ghfgh",
"objetivoE": "fghfg",
"tags": "hfghhg",
"status": 0,
"user_id": 1,
"profe_id": null,
"created_at": "2018-03-30 16:33:47",
"updated_at": "2018-03-30 16:33:47"
}

my route is this that I have put in my file (routes)

Route::resource('projects','proyectoscontroler');

---- my routes Route list

        | POST      | projects                      | projects.store   | App\Http\Controllers\proyectoscontroler@store                          | web,auth     |
|        | GET|HEAD  | projects                      | projects.index   | App\Http\Controllers\proyectoscontroler@index                          | web,auth     |

This is my query, so that I can return the values

 public function show($id)
    {
    return  Proyecto::where('user_id','=',auth()->user()->id)->get();
    }

.... I was already reading more about this, is not this another topic, so to speak? Protect my routes with Tokens ?. If there is any other way then welcome it.

I'm working with laravel

    
asked by Alex Burke Cooper 31.03.2018 в 02:37
source

1 answer

2

It is not a way to "protect" the routes, but taking into account that you use axios, I would deliver the data only for ajax requests, injecting the request into the method and using the ajax () method to verify the type of request :

public function index(Request $request)
{
    if ($request->ajax()) {
        // mostrar o entregar resultados
    } else {
        return 'No se puede mostrar el resultado.'
    }
}
    
answered by 31.03.2018 / 05:09
source