D
D
dk-web2016-05-02 22:14:27
Laravel
dk-web, 2016-05-02 22:14:27

Storing data in session in Laravel?

I wrote such a controller to work with the session.

class SessionsController extends Controller
{
   	 public function start(Request $request)
    {
    $request->session()->regenerate();
    $request->session()->put('start', Carbon::now());

  	return response()->json(['active' => true]);
//Я запускаю новую сессию и прописываю ей время старта
    }

   	public function finish(Request $request)
    {

     $request->session()->put('finish', Carbon::now());
  	return response()->json(['active' => false]);
//Я делаю метку, что смена закрыта и прописываю ей время окончания
    }

    public function check(Request $request)
    {
//для проверки открыта ли смена при первичном заходе на страницу
      if ($request->session()->has('finish')) {
        return response()->json(['active' => false]);
      } else {
       return response()->json(['active' => true]);
      }
    }

    public function check_session(Request $request)
//кнопка для проверки содержания сессии...		    
{
      return $request->session()->all();
    }




}

Actually a couple of short questions... what is payload?
The ultimate task is for me to fix the start time of the session and the time of its destruction... roughly speaking, create created_at and finished_at...
In the table of orders, I bind to the created session... but the check function that I call after the start function gives out that the field finish is present ....
I'm doing something wrong (

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D', 2016-05-02
@Denormalization

1) payload - stuffing. What needs to be saved.
2) If you do session()->flush() after session()->regenerate() - what happens?

R
Rustamka Vorontsov, 2016-05-03
@rmfordev

Well guys, what are the crutches, set up the session driver database and it will be easier to live) and created_at will be updated_at

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question