<commit_before><?php

namespace App\Http\Controllers;
use App\UserDashboard;
use App\AppInstance;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;

class UserDashboardController extends Controller
{
    public function __construct() {
        $this->middleware('auth');
    }
    
    public function index() {
        $user_dashboard = UserDashboard::where('user_id','=',Auth::user()->id)->where('site_id','=',Auth::user()->site->id)->first();
        if(is_null($user_dashboard) || !isset($user_dashboard->config)){
            $config = '""';
        }else{
            $config = $user_dashboard->config;
        }
        
        return view('dashboard',['apps'=>AppInstance::whereIn('group_id',Auth::user()->groups)->with('app')->get(),'name'=>"Dashboard", 'config'=>$config]);
    }

    public function update(Request $request) {
        $user_dashboard = UserDashboard::where('user_id','=',Auth::user()->id)->where('site_id','=',Auth::user()->site->id)->first();
        if ($user_dashboard) {
            $user_dashboard->config = $request->get('config');
        } else {
            $user_dashboard = new UserDashboard();
            $user_dashboard->user_id = Auth::user()->id;
            $user_dashboard->site_id = Auth::user()->site->id;
            $user_dashboard->config = $request->get('config');<commit_msg>Potential Fix for Site specific user dashboard<commit_after><?php

namespace App\Http\Controllers;
use App\UserDashboard;
use App\AppInstance;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;

class UserDashboardController extends Controller
{
    public function __construct() {
        $this->middleware('auth');
    }
    
    public function index() {
        $user_dashboard = UserDashboard::where('user_id','=',Auth::user()->id)->where('site_id','=',Auth::user()->site->id)->first();
        if(is_null($user_dashboard) || !isset($user_dashboard->config)){
            $config = '""';
        }else{
            $config = $user_dashboard->config;
        }
        
        return view('dashboard',['apps'=>AppInstance::whereIn('group_id',Auth::user()->groups)->with('app')->get(),'name'=>"Dashboard", 'config'=>$config]);
    }

    public function update(Request $request) {
        $user_dashboard = UserDashboard::where('user_id','=',Auth::user()->id)->where('site_id','=',Auth::user()->site->id)->first();
        if ($user_dashboard) {
            $user_dashboard->config = $request->get('config');
        } else {
            $user_dashboard = new UserDashboard([
                'user_id'=>Auth::user()->id,
                'site_id'=>Auth::user()->site->id,
                'config'=>$request->get('config')]);
{'fraction_non_alphanumeric': 0.19605654761904762, 'fraction_numerical': 0.0, 'mean_word_length': 3.408196721311475, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5030978', 'n_tokens_mistral': 774, 'n_tokens_neox': 811, 'n_words': 108}